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. [Solved] QDialog as UserControl?
Forum Updated to NodeBB v4.3 + New Features

[Solved] QDialog as UserControl?

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 4.1k Views 1 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.
  • D Offline
    D Offline
    Davita
    wrote on last edited by
    #1

    Hi
    I have a QTreeWidget and a QStackedWidget on my dialog. Navigation occurs when user select's an item in QTreeWidget (QStackedWidget's currentIndex property is updated) and user sees another view.
    Now my problem is that, I have many view's in one dialog, which makes code maintenance a bit more difficult, because, all the view's declared in QStackedWidget's pages are declared and defined in one dialog class (it will become huge in time). So I thought about UserControl. If you are unfamiliar with .NET's UserControl's concept, it's a class which hosts several widgets and ui logic inside.
    But the problem is that (as far as I know) qt widgets doesn't support UserControls. So I made a little improvisation and created a new Dialog derived from QDialog, added my widgets and ui logic and hosted that dialog inside main window.

    @UserDialog *d = new UserDialog(this);
    ui->verticalLayout_2->addWidget(d);@
    As you can see, UserDialog is not a widget, but a QDialog (still QDialog derives from QWidget). If I use this approach, my problems are easily fixed, but I don't know if it's safe, I mean, if this approach is discouraged or it has some drawbacks. What do you think? Is it ok to host QDialog as a widget in another dialog?

    Thanks

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      I don't get your question? What are your concerned about? Is it about subclassing QDialog at all? If so, go ahead! If a class is not supposed to be subclassed, it's stated in the docs (or does not make sense at all). Btw.. if you look at the docs of QDialog you will see:

      bq. Inherited by: Q3FileDialog, Q3ProgressDialog, Q3TabDialog, Q3Wizard, QAbstractPrintDialog, QColorDialog, QErrorMessage, QFileDialog, QFontDialog, QInputDialog, QMessageBox, QPageSetupDialog, QPrintPreviewDialog, QProgressDialog, and QWizard.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Davita
        wrote on last edited by
        #3

        No, that's not my question. I'm not fluent in English, so sorry for that :)
        My question is if I can use QDialog, just like I use any other widgets. For example, I can add QPushButton, QTreeView or any other widget on my dialog. I want to know, instead of adding QPushButton or any other widget, what if I add another dialog in a dialog :D just like I do with other widgets. I already tested this approach and it works fine, but I want to know if this approach is not recommended/discouraged.

        Thanks again :)

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          You can - in the sense of the compiler will not moan. But you're not supposed to. A QDialog ist always a toplevel widget, it does not make sense to add it into another toplevel widget.

          I don't know the concept of that UserControl - never got my hands dirty at .NET :-) if you would like to describe that functionality a bit more, we may come with an alternative solution for you.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            I think, that instead of using a QDialog as your base class, you should use a plain QWidget or perhaps a QFrame or something like that. That will allow you create a composite widget that is very easy to embed in a larger composition. QDialog is mend for toplevel use, as Volker already mentioned.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              Davita
              wrote on last edited by
              #6

              Thanks andre. Is it possible to use the designer with QWidget or QFrame controls? If so, how? :(
              sorry for the stupid question

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                Yes, you can. When you start a new file with designer, you can choose QMainWindow, QDialog or QWidget based. Take the QWidget based one, and you're all set.

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  Davita
                  wrote on last edited by
                  #8

                  @Andre, ouch, how could I miss that :)
                  Thank you very much, I appreciate your help :)

                  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