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

Embed QDialog as QWidget

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 483 Views 2 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.
  • Andy314A Offline
    Andy314A Offline
    Andy314
    wrote on last edited by Andy314
    #1

    Hello,
    I found a new feature of Qt what could help much for my projects.

    Background:
    The current version of my software consist of a lot of MID- and modal dialogs for the work flow. Now, my customer wants a more compact design, where all work will be executed in more or less in ONE window.
    Reprogram all funktion in this ONE window or in QFrames is a lot of work.

    Solution:
    A very elegant methode is, to ingegrate my derived QDialog in a Layout as a widget. This works like a charme, without much effort ! Nevertheless I read in the internet this is strict not recommend !
    Has somebody experiences with this methode ? Has it big disadvantages or produces problems later ?

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

      Hi,

      Depending on the logic you put in your dialogs, a search and replace to change the base class from QDialog to QWidget should be enough.

      That said, the usual issue with the cases reported online were from people trying to use QDialog as a base class for no good reason or trying to abuse its API.

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

      Andy314A 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        Depending on the logic you put in your dialogs, a search and replace to change the base class from QDialog to QWidget should be enough.

        That said, the usual issue with the cases reported online were from people trying to use QDialog as a base class for no good reason or trying to abuse its API.

        Andy314A Offline
        Andy314A Offline
        Andy314
        wrote on last edited by
        #3

        @SGaist said in Embed QDialog as QWidget:

        Hi,

        Depending on the logic you put in your dialogs, a search and replace to change the base class from QDialog to QWidget should be enough.

        That said, the usual issue with the cases reported online were from people trying to use QDialog as a base class for no good reason or trying to abuse its API.

        Hi,
        I dont understand what you mean, with the replacing.
        My stratgie is much more simpler, because I use the QDialog directy.

        class MyDialog: public QDialog 
        {....
        }
        
        // in an other dialog: 
        MyDialog* f=new MyDialog(this);
        ui->A_QFrame->layout()->addWidget(f);
        
        

        So I can use my dialog twice as a standard allone window and as a integration in an other dialog if i want.

        jsulmJ 1 Reply Last reply
        0
        • Andy314A Andy314

          @SGaist said in Embed QDialog as QWidget:

          Hi,

          Depending on the logic you put in your dialogs, a search and replace to change the base class from QDialog to QWidget should be enough.

          That said, the usual issue with the cases reported online were from people trying to use QDialog as a base class for no good reason or trying to abuse its API.

          Hi,
          I dont understand what you mean, with the replacing.
          My stratgie is much more simpler, because I use the QDialog directy.

          class MyDialog: public QDialog 
          {....
          }
          
          // in an other dialog: 
          MyDialog* f=new MyDialog(this);
          ui->A_QFrame->layout()->addWidget(f);
          
          

          So I can use my dialog twice as a standard allone window and as a integration in an other dialog if i want.

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

          @Andy314 said in Embed QDialog as QWidget:

          I dont understand what you mean, with the replacing

          Search and replace ": public QDialog" to ": public QWidget".

          "So I can use my dialog twice as a standard allone window and as a integration in an other dialog if i want" - the correct approach for this would be to create a QWidget based class which you can use directly or put in a QDialog.

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

          Andy314A 1 Reply Last reply
          1
          • jsulmJ jsulm

            @Andy314 said in Embed QDialog as QWidget:

            I dont understand what you mean, with the replacing

            Search and replace ": public QDialog" to ": public QWidget".

            "So I can use my dialog twice as a standard allone window and as a integration in an other dialog if i want" - the correct approach for this would be to create a QWidget based class which you can use directly or put in a QDialog.

            Andy314A Offline
            Andy314A Offline
            Andy314
            wrote on last edited by Andy314
            #5

            @jsulm said in Embed QDialog as QWidget:

            @Andy314 said in Embed QDialog as QWidget:

            I dont understand what you mean, with the replacing

            Search and replace ": public QDialog" to ": public QWidget".

            "So I can use my dialog twice as a standard allone window and as a integration in an other dialog if i want" - the correct approach for this would be to create a QWidget based class which you can use directly or put in a QDialog.

            Ok, I undsterstand. Transform the QDialog to a QWidget and use it as base with promoting in other dialogs is the cleanest solution. Nevertheless it works without this transformation too. The questions is, if later Qt-Version will break this technik.

            For my project its a little more compilcated, because my dialogs have not the QDialog as direct parent. I have my specialized dialog in chain of inherience with a lot of fundamental functions/communication/model-view interface .
            So the direct integration of the dialog will be easier, but mybe I will integrate it in a derived QWidget too.

            jsulmJ 1 Reply Last reply
            0
            • Andy314A Andy314

              @jsulm said in Embed QDialog as QWidget:

              @Andy314 said in Embed QDialog as QWidget:

              I dont understand what you mean, with the replacing

              Search and replace ": public QDialog" to ": public QWidget".

              "So I can use my dialog twice as a standard allone window and as a integration in an other dialog if i want" - the correct approach for this would be to create a QWidget based class which you can use directly or put in a QDialog.

              Ok, I undsterstand. Transform the QDialog to a QWidget and use it as base with promoting in other dialogs is the cleanest solution. Nevertheless it works without this transformation too. The questions is, if later Qt-Version will break this technik.

              For my project its a little more compilcated, because my dialogs have not the QDialog as direct parent. I have my specialized dialog in chain of inherience with a lot of fundamental functions/communication/model-view interface .
              So the direct integration of the dialog will be easier, but mybe I will integrate it in a derived QWidget too.

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

              @Andy314 said in Embed QDialog as QWidget:

              For my project its a little more compilcated, because my dialogs have not the QDialog as direct parent

              They don't have to. You can put any QWidget into a QDialog. QDialog is a QWidget, so you can add layouts and widgets to it.

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

              1 Reply Last reply
              2
              • Andy314A Andy314 has marked this topic as solved on

              • Login

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