Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1036649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:44:21+00:00 2026-05-16T14:44:21+00:00

I tried to create a Mainwindow with an slot, which creates a Widget and

  • 0

I tried to create a Mainwindow with an slot, which creates a Widget and loads it to the ScrollArea in the Mainwindow. This doesn’t work, so I tired to create the Widget in the constructor of the mainwindow and I always get errors and don’t know why.. so what’s the right declaration of the Widget?

#include <QtGui>


class Mainwindow : public QMainWindow
{
    Q_OBJECT

public:
    Mainwindow(QMainWindow *parent = 0);

public slots:

private:
    QScrollArea *List,*Sublist,*Overall,*Settings;
    QLabel *label_title;
    QPushButton *bn_exit,*bn_list,*bn_overall,*bn_settings;
};

//! ------------------------------------- Mainlist -------------------------------------
class Sublist : public QWidget{
 Q_OBJECT
private:
    QLabel *title;
public:
    Sublist(QWidget *parent = 0);
};

and .cpp

Mainwindow::Mainwindow(QMainWindow *parent) : QMainWindow(parent) {

    this->resize(1024,576);
    //this->setWindowFlags(Qt::Popup);
    QPalette palette;
    palette.setColor(QPalette::Background, QColor(16,16,16));
    this->setPalette(palette);

    Sublist SecondList;

    //! [Set ScrollAreas]
    List = new QScrollArea(this);
    List->setGeometry(0,60,200,456);
    List->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);

    Sublist = new QScrollArea(this);
    Sublist->setGeometry(200,60,824,456);
    Sublist->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
    //Sublist->setWidget(SecondList)

}

//! ---------------------------------------- MainList------------------------------------------------------
Sublist::Sublist(QWidget *parent){
    resize(1200,1200);
    title = new QLabel("Title",this);
    title->setGeometry(1120,1120,40,90);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T14:44:21+00:00Added an answer on May 16, 2026 at 2:44 pm

    I have played around with your code a bit, noticed a few things:

    In class Mainwindow you define your QScrollArea variables:

    QScrollArea *List,*Sublist,*Overall,*Settings;
    

    You define a variable named Sublist of type QScrollArea, but you also have a class of the same name:

    class Sublist : public QWidget
    

    Probably would be a good idea to change the variable names for your scroll areas:

    QScrollArea *list, *subList, *overall, *settings;
    

    Next, in the constructor for class Sublist you pass a pointer to the parent class but never assign it to your base class. You also have a QLabel widget that never is placed anywhere. What seems to be needed is a layout for your custom widget.

    The Sublist class could be something like this:

    //.h
    class Sublist : public QWidget
    {
        Q_OBJECT
    
    public:
        Sublist(QWidget *parent = 0);
    
    private:
        QLabel *title;
        QVBoxLayout *layout;
    };
    
    //.cpp
    Sublist::Sublist(QWidget *parent) : QWidget(parent) {
        resize(1200,1200);
        title = new QLabel("Title");
        title->setGeometry(1120,1120,40,90);
    
        QVBoxLayout *layout = new QVBoxLayout;
        layout->addWidget(title);
        setLayout(layout);
    }
    

    The Mainwindow class something like this:

    //.h
    class Mainwindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        Mainwindow(QMainWindow *parent = 0);
    
    private:
        Sublist *secondList;
        QScrollArea *list, *subList, *overall, *settings;
        QLabel *label_title;
        QPushButton *bn_exit,*bn_list,*bn_overall,*bn_settings;
    };
    
    //.cpp
    Mainwindow::Mainwindow(QMainWindow *parent) : QMainWindow(parent) 
    {
        this->resize(1024,576);
        QPalette palette;
        palette.setColor(QPalette::Background, QColor(16,16,16));
        palette.setColor(QPalette::Foreground, QColor(255,255,255));//set text to white
        this->setPalette(palette);
    
        secondList = new Sublist(this);
    
        //! [Set ScrollAreas]
        list = new QScrollArea(this);
        list->setGeometry(0,60,200,456);
        list->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
    
        subList = new QScrollArea(this);
        subList->setGeometry(200,60,824,456);
        subList->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
        subList->setWidget(secondList);
    }
    

    Im still not 100% sure this is what you where trying to achieve with this code, but I hope that I have helped you to resolve some of the issues in your current implementation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I amk new to qt. I tried to create a window with a widget.
I have a Qt Designer Class called MainWindow which is a QMainWindow. This class
UPDATE 3: I created a Visual Studio 2008 test project and tried to create
I am very, very new to MYSQL.I tried to create a table named option.
I have tried to find how to create DLL-s on linux using google, but
how to create a shortcut for a exe from a batch file. i tried
Tried something like this: HttpApplication app = s as HttpApplication; //s is sender of
I tried scouring the web for help on this issue, but there are so
I would like to create sample data which are created only in design mode
When you create a new application in Xcode, it automatically creates a AppDelegate and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.