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. Problem with inheritance and QDialog
Forum Updated to NodeBB v4.3 + New Features

Problem with inheritance and QDialog

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 4 Posters 964 Views 3 Watching
  • 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.
  • S Offline
    S Offline
    Stefanoxjx
    wrote on last edited by
    #3

    Hi JonB,
    please, have patient, I don't know C++ very well and I try to experimented to understand.
    If you look in GenericLists.cpp you can find this:

        QVBoxLayout *layout = new QVBoxLayout;
        layout->addWidget(mainWindow);
        setLayout(layout);
    

    I think that layout must inherited from JobList

    I think wrong?

    JonBJ 1 Reply Last reply
    0
    • S Stefanoxjx

      Hi JonB,
      please, have patient, I don't know C++ very well and I try to experimented to understand.
      If you look in GenericLists.cpp you can find this:

          QVBoxLayout *layout = new QVBoxLayout;
          layout->addWidget(mainWindow);
          setLayout(layout);
      

      I think that layout must inherited from JobList

      I think wrong?

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #4

      @Stefanoxjx
      I am patient, but I don't know what you're trying to do! Maybe you mean layout()->addLayout(...)? Maybe you mean setLayout(hl1), is that what you're trying to do?

      Completely separate from your question. First, you do not want to be going this->exec(); in the JobsList::JobsList() constructor at all. Only the caller who creates this dialog should call exec(). Second, you are creating a QMainWindow inside a dialog; technically thins works, but it's an odd thing to want to do, main windows should be windows, not inside dialogs.

      S 1 Reply Last reply
      2
      • JonBJ JonB

        @Stefanoxjx
        I am patient, but I don't know what you're trying to do! Maybe you mean layout()->addLayout(...)? Maybe you mean setLayout(hl1), is that what you're trying to do?

        Completely separate from your question. First, you do not want to be going this->exec(); in the JobsList::JobsList() constructor at all. Only the caller who creates this dialog should call exec(). Second, you are creating a QMainWindow inside a dialog; technically thins works, but it's an odd thing to want to do, main windows should be windows, not inside dialogs.

        S Offline
        S Offline
        Stefanoxjx
        wrote on last edited by
        #5

        You're right, excuse me for omission...

        @JonB said in Problem with inheritance and QDialog:

        @Stefanoxjx
        I am patient, but I don't know what you're trying to do! Maybe you mean layout()->addLayout(...)? Maybe you mean setLayout(hl1), is that what you're trying to do?

        I would like to add layout with: layout().addlayout(hl1), but under layout() I found only methods: activate, addItem, addWidget, alignment.

        Completely separate from your question. First, you do not want to be going this->exec(); in the JobsList::JobsList(0 constructor at all. Only the caller who creates this dialog should call exec().

        Ops!!!
        I've many dialogs with same toolbar, changes only the body of dialog.
        What's the better way to have dialog creation and toolbar managed from single class?

        Second, you are creating a QMainWindow inside a dialog; technically thins works, but it;s an odd thing to want to do, main windows should be windows, not inside dialogs.

        About this, I've seen this method in StackOverflow: https://stackoverflow.com/questions/18435801/can-you-add-a-toolbar-to-qdialog

        Maybe I've to create QMainWindow instead QDialog?

        JonBJ 1 Reply Last reply
        0
        • S Stefanoxjx

          You're right, excuse me for omission...

          @JonB said in Problem with inheritance and QDialog:

          @Stefanoxjx
          I am patient, but I don't know what you're trying to do! Maybe you mean layout()->addLayout(...)? Maybe you mean setLayout(hl1), is that what you're trying to do?

          I would like to add layout with: layout().addlayout(hl1), but under layout() I found only methods: activate, addItem, addWidget, alignment.

          Completely separate from your question. First, you do not want to be going this->exec(); in the JobsList::JobsList(0 constructor at all. Only the caller who creates this dialog should call exec().

          Ops!!!
          I've many dialogs with same toolbar, changes only the body of dialog.
          What's the better way to have dialog creation and toolbar managed from single class?

          Second, you are creating a QMainWindow inside a dialog; technically thins works, but it;s an odd thing to want to do, main windows should be windows, not inside dialogs.

          About this, I've seen this method in StackOverflow: https://stackoverflow.com/questions/18435801/can-you-add-a-toolbar-to-qdialog

          Maybe I've to create QMainWindow instead QDialog?

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by JonB
          #6

          @Stefanoxjx said in Problem with inheritance and QDialog:

          I would like to add layout with: layout().addlayout(hl1), but under layout() I found only methods: activate, addItem, addWidget, alignment.

          It would be layout()->addlayout(hl1). OK, I get it, layout() returns QLayout* and it doesn't know of yours is a QBoxLayout* for addLayout(). This could be addressed, but I'm not convinced you even want to be doing an addLayout() here....

          What's the better way to have dialog creation and toolbar managed from single class?

          The dialog's constructor is for creating the dialog. Not for showing/executing it. the caller --- the one who does dialog = new QDialog() --- is the place to go dialog->exec().

          I accept one can put a toolbar, or a main window, in dialogs. The question is why would you want to? Why do you have dialogs which you want to look like main windows with toolbars etc.? The real question is: why dialogs?

          If you can get rid of the need for dialogs, a common scenario is to have a QMainWindow --- so it has a common toolbar, menu etc. --- with the main widget being a QStackedWidget which holds "pages" (widgets) in the central area. Users clicks/takes actions and which one page is being shown in the main window changes appropriately. Is something like that what you want?

          S 1 Reply Last reply
          1
          • JonBJ JonB

            @Stefanoxjx said in Problem with inheritance and QDialog:

            I would like to add layout with: layout().addlayout(hl1), but under layout() I found only methods: activate, addItem, addWidget, alignment.

            It would be layout()->addlayout(hl1). OK, I get it, layout() returns QLayout* and it doesn't know of yours is a QBoxLayout* for addLayout(). This could be addressed, but I'm not convinced you even want to be doing an addLayout() here....

            What's the better way to have dialog creation and toolbar managed from single class?

            The dialog's constructor is for creating the dialog. Not for showing/executing it. the caller --- the one who does dialog = new QDialog() --- is the place to go dialog->exec().

            I accept one can put a toolbar, or a main window, in dialogs. The question is why would you want to? Why do you have dialogs which you want to look like main windows with toolbars etc.? The real question is: why dialogs?

            If you can get rid of the need for dialogs, a common scenario is to have a QMainWindow --- so it has a common toolbar, menu etc. --- with the main widget being a QStackedWidget which holds "pages" (widgets) in the central area. Users clicks/takes actions and which one page is being shown in the main window changes appropriately. Is something like that what you want?

            S Offline
            S Offline
            Stefanoxjx
            wrote on last edited by
            #7

            @JonB said in Problem with inheritance and QDialog:

            If you can get rid of the need for dialogs, a common scenario is to have a QMainWindow --- so it has a common toolbar, menu etc. --- with the main widget being a QStackedWidget which holds "pages" (widgets) in the central area. Users clicks/takes actions and which one page is being shown in the main window changes appropriately. Is something like that what you want?

            Yes I can get rid of QDialog and have only one MainWindow with internal Widgets, but I can have user interface with many widgets and another with a single QLineedit.
            The latter would look very bad in a large QMainWindow (a drop of water in the middle of the desert :D)
            With QDialog I thought to minimize this case because I can have a QDialog with properly size about number of widget.
            I hope I explained good :)

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #8

              Hi,

              Can you explain a bit more what your application does with that variety of widgets ?

              There might lie the idea for a good UI design.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Stefanoxjx
                wrote on last edited by
                #9

                Hi,
                simply, the application can have forms with a single QLabel+QLineEdit to edit a table with one column and forms with many Widgets to manage Tables with many Columns.
                I don't like use QTableWidget to do it, I prefer a classic form.
                If I create a QMainWindow with appropriate dimension to insert many widgets and after I use same QMainWindow to place a single QLabel+QLineEdit you understand that UI it will suck :(

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #10

                  Are-you using QDataWidgetMapper ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    Stefanoxjx
                    wrote on last edited by
                    #11

                    Not at the moment.

                    mrjjM 1 Reply Last reply
                    0
                    • S Stefanoxjx

                      Not at the moment.

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #12

                      @Stefanoxjx
                      Hi
                      The layout in the base class is just a local variable
                      QVBoxLayout *layout = new QVBoxLayout;

                      So to access this from a base class you need to store it as a member variable in
                      GenericLists.h (in the class def) so it can be inherited so to speak.

                      so in .h
                      QVBoxLayout *layout;

                      and then instead in .cpp
                      layout = new QVBoxLayout;

                      Then your JobsList can also use it.

                      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