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. QDialog Inheritance
Forum Updated to NodeBB v4.3 + New Features

QDialog Inheritance

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 5 Posters 1.4k Views 4 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.
  • U Offline
    U Offline
    U7Development
    wrote on last edited by
    #1

    Hi!
    I have 10 dialog windows, where at least 5 of them use the same scheme, i mean, same buttons, fixed window sizes and tables, just some names changes... and i was wondering if i can inheritance with it...

    something like this:
    SuperClass_QDialogType : QDialog
    MainDialogWindowType : SuperClass_QDialogType
    WBuyDialog : MainDialogWindowType
    WSellDialog : MainDialogWindowType
    WAskDialog : MainDialogWindowType
    ..and so.

    MainDialogWindowType has all slots and signal for buttons and the table...

    Does it has sense o better stay with no-inheritance with windows?

    Thanks.

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

      Hi,

      Yes, it does make sense to write reusable widgets.

      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
      1
      • U Offline
        U Offline
        U7Development
        wrote on last edited by
        #3

        ok!... does the MainDialogWindowType needs to be a simple class or a Qt Designer form class in order to use slots and signals?

        mrjjM 1 Reply Last reply
        0
        • U U7Development

          ok!... does the MainDialogWindowType needs to be a simple class or a Qt Designer form class in order to use slots and signals?

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

          @U7Development
          Hi
          Any class that inherits from QObject/QWidget and has the Q_OBJECT
          macro can use signals and slots. So you dont have to use Designer if not needed.

          However, QDialog has the option of being modal which QWidgets cannot.

          Chris KawaC 1 Reply Last reply
          2
          • mrjjM mrjj

            @U7Development
            Hi
            Any class that inherits from QObject/QWidget and has the Q_OBJECT
            macro can use signals and slots. So you dont have to use Designer if not needed.

            However, QDialog has the option of being modal which QWidgets cannot.

            Chris KawaC Offline
            Chris KawaC Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @mrjj said:

            However, QDialog has the option of being modal which QWidgets cannot.

            They can: modal ;)

            mrjjM 1 Reply Last reply
            4
            • Chris KawaC Chris Kawa

              @mrjj said:

              However, QDialog has the option of being modal which QWidgets cannot.

              They can: modal ;)

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

              @Chris-Kawa
              Oh that i completely missed! :) ( years later :)
              So it can also spin local event loop and behave like QDialog ?
              So the only real added feature of dialogs is what ever the platform adds for the windows flags and the accept / reject system ?
              Or what does QDialog bring that QWidget cannot ?

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mpergand
                wrote on last edited by mpergand
                #7

                I'm not convince inheritance is the easier way for managing a few minor label/text changes AMHA.

                One can define a Dialog type attribut instead:

                enum DialogType
                {
                Buy, Sell, Ask
                };
                
                DialogWindow(DialogType type, QWidget* parent=nullptr) : QDialog(parent)
                {
                  switch(type)
                  {
                  case Buy:
                 // make changes for Buy type
                  break;
                
                  ...
                
                  }
                }
                
                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  So a bit like QMessageBox or QInputDialog ?

                  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
                  1

                  • Login

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