Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to customize a class, for use in our program
Qt 6.12 LTS is out! See what's new in the release blog

How to customize a class, for use in our program

Scheduled Pinned Locked Moved Solved General and Desktop
24 Posts 2 Posters 9.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • jsulmJ jsulm

    @o6a6r9v1p Well just put that code in a private method in your main window and call it in the constructor.
    The thing is: TabDialog is a dialog. Do you want to use it as such in your app (means: do you want to show a dialog window in your app)?

    O Offline
    O Offline
    o6a6r9v1p
    wrote on last edited by
    #13

    @jsulm
    TabDialog is a class constructor & is used to build top level Tabbed windows.
    This in turn uses 3 more classes, each class used to build one tab of the window.
    the code for TabDialog is
    @
    TabDialog::TabDialog(const QString &fileName, QWidget *parent)
    : QDialog(parent)
    {
    QFileInfo fileInfo(fileName);

    tabWidget = new QTabWidget;
    tabWidget->addTab(new DashBoardTab(fileInfo), tr("DashBoard"));
    tabWidget->addTab(new SettingsTab(fileInfo), tr("Settings"));
    tabWidget->addTab(new ValuesTab(fileInfo), tr("Values"));
    
    buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
                                     | QDialogButtonBox::Cancel);
    QLabel *fileNameLabel = new QLabel(tr("File Name:"));
    QLabel *label_Status = new QLabel(tr("Status"));
    label_Status->setObjectName(QString::fromUtf8("Status"));
    label_Status->setEnabled(true);
    label_Status->setGeometry(QRect(410, 10, 41, 21));
    label_Status->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
    QLineEdit *deviceConnectedStatus = new QLineEdit();
    deviceConnectedStatus->setObjectName(QString::fromUtf8("deviceConnectedStatus"));
    deviceConnectedStatus->setEnabled(true);
    deviceConnectedStatus->setGeometry(QRect(20, 10, 391, 20));
    deviceConnectedStatus->setReadOnly(true);
    
    
    QHBoxLayout *statusLayout = new QHBoxLayout;
    statusLayout->addWidget(deviceConnectedStatus);
    statusLayout->addWidget(label_Status);
    
    connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
    connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
    
    QVBoxLayout *mainLayout = new QVBoxLayout;
    
    mainLayout->addLayout(statusLayout);
    mainLayout->addWidget(tabWidget);
    mainLayout->addWidget(buttonBox);
    setLayout(mainLayout);
    
    setWindowTitle(tr("Device Monitor"));
    

    }

    @

    DashBoardTab(fileInfo) , SettingsTab(fileInfo), ValuesTab(fileInfo) are 3 classes for 3 tabs

    1 Reply Last reply
    0
    • jsulmJ jsulm

      @o6a6r9v1p Well just put that code in a private method in your main window and call it in the constructor.
      The thing is: TabDialog is a dialog. Do you want to use it as such in your app (means: do you want to show a dialog window in your app)?

      O Offline
      O Offline
      o6a6r9v1p
      wrote on last edited by
      #14

      @jsulm
      yes, i want to show dialog window.

      jsulmJ 1 Reply Last reply
      0
      • O o6a6r9v1p

        @jsulm
        yes, i want to show dialog window.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #15

        @o6a6r9v1p In this case you should not create the TabDialog instance in the constructor of your main window. Instead do it when you want to show it (user clicks a button or menu or whatever).

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        O 1 Reply Last reply
        0
        • jsulmJ jsulm

          @o6a6r9v1p In this case you should not create the TabDialog instance in the constructor of your main window. Instead do it when you want to show it (user clicks a button or menu or whatever).

          O Offline
          O Offline
          o6a6r9v1p
          wrote on last edited by
          #16

          @jsulm
          is it possible to start with 1st tab by default.
          Top row: device status
          below this Tabbed window is needed. it has to start with Tab0 default. As we click other tabs, we have to change.

          jsulmJ 1 Reply Last reply
          0
          • O o6a6r9v1p

            @jsulm
            is it possible to start with 1st tab by default.
            Top row: device status
            below this Tabbed window is needed. it has to start with Tab0 default. As we click other tabs, we have to change.

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #17

            @o6a6r9v1p
            Sorry, I don't understand your description: what is "Top row"? What is "device status"? First you ask whether it is possible to start with tab1 and then you say it has to start with Tab0, I'm confused.
            It is possible to activate a specific tab, read documentation: http://doc.qt.io/qt-5/qtabwidget.html#currentIndex-prop

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            O 1 Reply Last reply
            0
            • jsulmJ jsulm

              @o6a6r9v1p
              Sorry, I don't understand your description: what is "Top row"? What is "device status"? First you ask whether it is possible to start with tab1 and then you say it has to start with Tab0, I'm confused.
              It is possible to activate a specific tab, read documentation: http://doc.qt.io/qt-5/qtabwidget.html#currentIndex-prop

              O Offline
              O Offline
              o6a6r9v1p
              wrote on last edited by
              #18

              @jsulm
              sorry, it is typing mistake. tab0 it is.
              How to add image here.
              I have created image in Paint, which i can post here

              jsulmJ 1 Reply Last reply
              0
              • O o6a6r9v1p

                @jsulm
                sorry, it is typing mistake. tab0 it is.
                How to add image here.
                I have created image in Paint, which i can post here

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #19

                @o6a6r9v1p Posting images usually does not work here. You can upload it to a sharing service and post the link here.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                O 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @o6a6r9v1p Posting images usually does not work here. You can upload it to a sharing service and post the link here.

                  O Offline
                  O Offline
                  o6a6r9v1p
                  wrote on last edited by
                  #20

                  @jsulm
                  Hi, Link for the image is
                  https://drive.google.com/open?id=0B-mEoDT_Dr1NajRQQWoyeDNYMTQ

                  jsulmJ 1 Reply Last reply
                  0
                  • O o6a6r9v1p

                    @jsulm
                    Hi, Link for the image is
                    https://drive.google.com/open?id=0B-mEoDT_Dr1NajRQQWoyeDNYMTQ

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #21

                    @o6a6r9v1p Sure, it is possible.
                    Check their code (constructor) and extend it like this:

                    QVBoxLayout *mainLayout = new QVBoxLayout;
                    QHBoxLayout *topRowLayout = new QHBoxLayout;
                    QLineEdit *lineEdit = new QLineEdit(this);
                    QLabel *label = new QLabel(this);
                    topRowLayout.addWidget(lineEdit);
                    topRowLayout.addWidget(label);
                    mainLayout->addLayout(topRowLayout);
                    mainLayout->addWidget(tabWidget);
                    mainLayout->addWidget(buttonBox);
                    setLayout(mainLayout);
                    

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    O 1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @o6a6r9v1p Sure, it is possible.
                      Check their code (constructor) and extend it like this:

                      QVBoxLayout *mainLayout = new QVBoxLayout;
                      QHBoxLayout *topRowLayout = new QHBoxLayout;
                      QLineEdit *lineEdit = new QLineEdit(this);
                      QLabel *label = new QLabel(this);
                      topRowLayout.addWidget(lineEdit);
                      topRowLayout.addWidget(label);
                      mainLayout->addLayout(topRowLayout);
                      mainLayout->addWidget(tabWidget);
                      mainLayout->addWidget(buttonBox);
                      setLayout(mainLayout);
                      
                      O Offline
                      O Offline
                      o6a6r9v1p
                      wrote on last edited by
                      #22

                      @jsulm
                      In side tabWidget, I need 3 tabs. In that example code, they have used separate classes for them. Now I will do as you suggested.

                      In this, i am getting signal from abcd(child) class and it is to be connected to(parent class) updateGui() in this function.
                      how to connect them.

                      jsulmJ 1 Reply Last reply
                      0
                      • O o6a6r9v1p

                        @jsulm
                        In side tabWidget, I need 3 tabs. In that example code, they have used separate classes for them. Now I will do as you suggested.

                        In this, i am getting signal from abcd(child) class and it is to be connected to(parent class) updateGui() in this function.
                        how to connect them.

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #23

                        @o6a6r9v1p You do not need to use separate classes for your tabs, but you can if you like. Please read documentation: http://doc.qt.io/qt-5/qtabwidget.html#details
                        it is explained there:
                        "Create a QTabWidget.
                        Create a QWidget for each of the pages in the tab dialog, but do not specify parent widgets for them.
                        Insert child widgets into the page widget, using layouts to position them as normal.
                        Call addTab() or insertTab() to put the page widgets into the tab widget, giving each tab a suitable label with an optional keyboard shortcut."

                        How to connect signals/slots? What exactly is the problem? Do it in your parent class where you create the children, for example:

                        tabWidget = new QTabWidget;
                        DashBoardTab *dashBoardTab = new DashBoardTab(fileInfo);
                        connect(dashBoardTab, SIGNAL(someSignal()), this, SLOT(someSlot()));
                        tabWidget->addTab(dashBoardTab, tr("DashBoard"));
                        tabWidget->addTab(new SettingsTab(fileInfo), tr("Settings"));
                        tabWidget->addTab(new ValuesTab(fileInfo), tr("Values"));
                        

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        O 1 Reply Last reply
                        1
                        • jsulmJ jsulm

                          @o6a6r9v1p You do not need to use separate classes for your tabs, but you can if you like. Please read documentation: http://doc.qt.io/qt-5/qtabwidget.html#details
                          it is explained there:
                          "Create a QTabWidget.
                          Create a QWidget for each of the pages in the tab dialog, but do not specify parent widgets for them.
                          Insert child widgets into the page widget, using layouts to position them as normal.
                          Call addTab() or insertTab() to put the page widgets into the tab widget, giving each tab a suitable label with an optional keyboard shortcut."

                          How to connect signals/slots? What exactly is the problem? Do it in your parent class where you create the children, for example:

                          tabWidget = new QTabWidget;
                          DashBoardTab *dashBoardTab = new DashBoardTab(fileInfo);
                          connect(dashBoardTab, SIGNAL(someSignal()), this, SLOT(someSlot()));
                          tabWidget->addTab(dashBoardTab, tr("DashBoard"));
                          tabWidget->addTab(new SettingsTab(fileInfo), tr("Settings"));
                          tabWidget->addTab(new ValuesTab(fileInfo), tr("Values"));
                          
                          O Offline
                          O Offline
                          o6a6r9v1p
                          wrote on last edited by
                          #24

                          @jsulm
                          Thank you very much. Now I am able to get the tabs.

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt
                          • Unsolved