Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to customize a class, for use in our program
Forum Updated to NodeBB v4.3 + New Features

How to customize a class, for use in our program

Scheduled Pinned Locked Moved Solved General and Desktop
24 Posts 2 Posters 7.4k 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.
  • O Offline
    O Offline
    o6a6r9v1p
    wrote on last edited by
    #1

    I have created a blank project in QT, trying to create GUI through program.
    This way I donot want to change ui_proj.h file.

    I need LineEdit box, a Label in a row. (put into a QHLayout)
    Below it I need a tabWidget, to display segregated info in different tabs.

    I tried the example given at
    http://doc.qt.io/qt-5/qtwidgets-dialogs-tabdialog-example.html
    it worked fine as a stand alone program.
    Now I want to adopt "TabDialog class" from that example in my project, so that I can put QHLayout and TabWidget into QVLayout .

    Name of my app's class is "demoapp" and namespace is "ui".
    where shall I change the program.

    jsulmJ 1 Reply Last reply
    0
    • O o6a6r9v1p

      I have created a blank project in QT, trying to create GUI through program.
      This way I donot want to change ui_proj.h file.

      I need LineEdit box, a Label in a row. (put into a QHLayout)
      Below it I need a tabWidget, to display segregated info in different tabs.

      I tried the example given at
      http://doc.qt.io/qt-5/qtwidgets-dialogs-tabdialog-example.html
      it worked fine as a stand alone program.
      Now I want to adopt "TabDialog class" from that example in my project, so that I can put QHLayout and TabWidget into QVLayout .

      Name of my app's class is "demoapp" and namespace is "ui".
      where shall I change the program.

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

      @o6a6r9v1p Usually you create your widgets in the constructor of the GUI class (I guess it is your main window).
      So, after ui->setupUi(this); you put the code to add needed widgets.

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

      O 1 Reply Last reply
      2
      • jsulmJ jsulm

        @o6a6r9v1p Usually you create your widgets in the constructor of the GUI class (I guess it is your main window).
        So, after ui->setupUi(this); you put the code to add needed widgets.

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

        @jsulm
        Thanks for it. How to include classes from other examples/projects. How to call constructor of other class in our code. In the tabWidget example, 4 classes are used. Can we use them with out rewriting code.

        jsulmJ 1 Reply Last reply
        0
        • O o6a6r9v1p

          @jsulm
          Thanks for it. How to include classes from other examples/projects. How to call constructor of other class in our code. In the tabWidget example, 4 classes are used. Can we use them with out rewriting code.

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

          @o6a6r9v1p Add the headers and cpp files containing those classes to your project (copy them into your project folder where your classes are) and use the classes. Don't forget to add those files to the pro file of your project, run qmake afterwards and rebuild. How to call a constructor of a class belongs to C++ basics:

          #include "SomeClass.h"
          
          MyClass::MyClass()
          {
              SomeClass *someClass = new SomeClass();
          }

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

          O 1 Reply Last reply
          2
          • jsulmJ jsulm

            @o6a6r9v1p Add the headers and cpp files containing those classes to your project (copy them into your project folder where your classes are) and use the classes. Don't forget to add those files to the pro file of your project, run qmake afterwards and rebuild. How to call a constructor of a class belongs to C++ basics:

            #include "SomeClass.h"
            
            MyClass::MyClass()
            {
                SomeClass *someClass = new SomeClass();
            }
            O Offline
            O Offline
            o6a6r9v1p
            wrote on last edited by
            #5

            @jsulm

            Did as told . This is code for main class.

            @

            DemoApp::DemoApp(QWidget *parent) :
            QMainWindow(parent),
            ui(new Ui::DemoApp)
            {
            TabDialog *tabdialog =new TabDialog();

            ui->setupUi(this);
            modifyUi(this);
            tabdialog(this);
            

            }

            @

            getting 'tabdialog' cannot be used as a function

            jsulmJ 2 Replies Last reply
            0
            • O o6a6r9v1p

              @jsulm

              Did as told . This is code for main class.

              @

              DemoApp::DemoApp(QWidget *parent) :
              QMainWindow(parent),
              ui(new Ui::DemoApp)
              {
              TabDialog *tabdialog =new TabDialog();

              ui->setupUi(this);
              modifyUi(this);
              tabdialog(this);
              

              }

              @

              getting 'tabdialog' cannot be used as a function

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

              @o6a6r9v1p tabdialog is a pointer, what do you want to achieve if you write tabdialog(this)?

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

              O 1 Reply Last reply
              0
              • O o6a6r9v1p

                @jsulm

                Did as told . This is code for main class.

                @

                DemoApp::DemoApp(QWidget *parent) :
                QMainWindow(parent),
                ui(new Ui::DemoApp)
                {
                TabDialog *tabdialog =new TabDialog();

                ui->setupUi(this);
                modifyUi(this);
                tabdialog(this);
                

                }

                @

                getting 'tabdialog' cannot be used as a function

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

                @o6a6r9v1p TabDialog is a dialog, that means it is going to be its own window. If you want to put the stuff from TabDialog into your main window then do not add it to your project but copy its code and put it into your main window.

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

                O 2 Replies Last reply
                0
                • jsulmJ jsulm

                  @o6a6r9v1p tabdialog is a pointer, what do you want to achieve if you write tabdialog(this)?

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

                  @jsulm
                  TabDialog is a class used to create a tabbed window. That class is defined and available at above referred link it is top level class, which creates a tabbed window, by using three more classes for three tabs.

                  O 1 Reply Last reply
                  0
                  • O o6a6r9v1p

                    @jsulm
                    TabDialog is a class used to create a tabbed window. That class is defined and available at above referred link it is top level class, which creates a tabbed window, by using three more classes for three tabs.

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

                    @o6a6r9v1p
                    it uses tabWidget

                    1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @o6a6r9v1p TabDialog is a dialog, that means it is going to be its own window. If you want to put the stuff from TabDialog into your main window then do not add it to your project but copy its code and put it into your main window.

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

                      @jsulm
                      it increases size of main ctor.

                      1 Reply Last reply
                      0
                      • jsulmJ jsulm

                        @o6a6r9v1p TabDialog is a dialog, that means it is going to be its own window. If you want to put the stuff from TabDialog into your main window then do not add it to your project but copy its code and put it into your main window.

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

                        @jsulm
                        copying code into main window increases size of ctor. want to aviod that.

                        jsulmJ 1 Reply Last reply
                        0
                        • O o6a6r9v1p

                          @jsulm
                          copying code into main window increases size of ctor. want to aviod that.

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

                          @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)?

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

                          O 2 Replies 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
                            #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

                                          • Login

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