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. Dynamic QWidget from QtDesigner form

Dynamic QWidget from QtDesigner form

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 3 Posters 578 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.
  • G Offline
    G Offline
    Gourmet
    wrote on last edited by
    #1

    What I am doing wrong? I need dynamic QWidget with form created in QtDesigner. It is heavily decorated dialog therefore I cannot use QMessageBox. All code works but widget does not appear visible. It appears invisible and blocks underlaying widgets (form is Application Modal).

    void SomeClass::dialog(const QString& text)
    {
        if( Dlg == Q_NULLPTR )
        {
            Dlg = new QWidget((QWidget*)parent()); //parent() here is QMainWindow's centralWidget
            ui->setupUi( Dlg ); // ui is common QtDesigner form, it's Ok
            Dlg->raise();
            Dlg->update();
            connect( ui->okButton, SIGNAL(pressed()), this, SLOT(dialogYes()) );
            connect( ui->noButton, SIGNAL(pressed()), this, SLOT(dialogNo()) );
        }
        ui->messageText->setText( text );
        Dlg->show();
    }
    

    I remember that I did this years ago - and all worked fine. But may be something changed in latest Qt versions (or I forget do something).

    jsulmJ 1 Reply Last reply
    0
    • G Gourmet

      What I am doing wrong? I need dynamic QWidget with form created in QtDesigner. It is heavily decorated dialog therefore I cannot use QMessageBox. All code works but widget does not appear visible. It appears invisible and blocks underlaying widgets (form is Application Modal).

      void SomeClass::dialog(const QString& text)
      {
          if( Dlg == Q_NULLPTR )
          {
              Dlg = new QWidget((QWidget*)parent()); //parent() here is QMainWindow's centralWidget
              ui->setupUi( Dlg ); // ui is common QtDesigner form, it's Ok
              Dlg->raise();
              Dlg->update();
              connect( ui->okButton, SIGNAL(pressed()), this, SLOT(dialogYes()) );
              connect( ui->noButton, SIGNAL(pressed()), this, SLOT(dialogNo()) );
          }
          ui->messageText->setText( text );
          Dlg->show();
      }
      

      I remember that I did this years ago - and all worked fine. But may be something changed in latest Qt versions (or I forget do something).

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

      @Gourmet Why don't you simply instantiate your form directly instead of creating a QWidget instance?

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

      G 1 Reply Last reply
      0
      • jsulmJ jsulm

        @Gourmet Why don't you simply instantiate your form directly instead of creating a QWidget instance?

        G Offline
        G Offline
        Gourmet
        wrote on last edited by Gourmet
        #3

        @jsulm instantinate directly? This is direct "instantination" as it is described in docs. And form appears - but invisible without clean reason. Of course it has windowOpacity = 1.0 in properties.

        jsulmJ 1 Reply Last reply
        0
        • G Gourmet

          @jsulm instantinate directly? This is direct "instantination" as it is described in docs. And form appears - but invisible without clean reason. Of course it has windowOpacity = 1.0 in properties.

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

          @Gourmet What I mean is:

          MyForm *myForm = new MyForm(parent());
          

          MyForm being your form created in designer.

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

          G 1 Reply Last reply
          1
          • jsulmJ jsulm

            @Gourmet What I mean is:

            MyForm *myForm = new MyForm(parent());
            

            MyForm being your form created in designer.

            G Offline
            G Offline
            Gourmet
            wrote on last edited by Gourmet
            #5

            @jsulm but in designer I have created just only UI XML file. And automatically generated ui_form.h file containing form init code. It requires QWidget to be shown.

            Can you tell why I do not see form with my code? If not - then show other solution completely, not only idea. I am straight on my code for while.

            jsulmJ 1 Reply Last reply
            0
            • G Gourmet

              @jsulm but in designer I have created just only UI XML file. And automatically generated ui_form.h file containing form init code. It requires QWidget to be shown.

              Can you tell why I do not see form with my code? If not - then show other solution completely, not only idea. I am straight on my code for while.

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

              @Gourmet I don't know why it is not visible. You could try the simple example from the doc with our ui to see whether it is visible:

              int main(int argc, char *argv[])
              {
                  QApplication app(argc, argv);
                  QWidget widget;
                  Ui::YOUR_UI_HERE ui;
                  ui.setupUi(&widget);
              
                  widget.show();
                  return app.exec();
              }
              

              Also you wrote: "It is heavily decorated dialog". What do you mean with "decorated"? Style-sheets?

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

              G 1 Reply Last reply
              1
              • jsulmJ jsulm

                @Gourmet I don't know why it is not visible. You could try the simple example from the doc with our ui to see whether it is visible:

                int main(int argc, char *argv[])
                {
                    QApplication app(argc, argv);
                    QWidget widget;
                    Ui::YOUR_UI_HERE ui;
                    ui.setupUi(&widget);
                
                    widget.show();
                    return app.exec();
                }
                

                Also you wrote: "It is heavily decorated dialog". What do you mean with "decorated"? Style-sheets?

                G Offline
                G Offline
                Gourmet
                wrote on last edited by
                #7

                @jsulm yes, style-sheets. The form is clearly visible in designer.

                The code you have shown is almost the same as mine. No significant difference.

                Pl45m4P 1 Reply Last reply
                0
                • G Gourmet

                  @jsulm yes, style-sheets. The form is clearly visible in designer.

                  The code you have shown is almost the same as mine. No significant difference.

                  Pl45m4P Offline
                  Pl45m4P Offline
                  Pl45m4
                  wrote on last edited by
                  #8

                  @Gourmet

                  What happens if you set your MainWindow as parent instead of the centralWidget? Or without any parent... Does it show up?


                  If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                  ~E. W. Dijkstra

                  G 1 Reply Last reply
                  0
                  • Pl45m4P Pl45m4

                    @Gourmet

                    What happens if you set your MainWindow as parent instead of the centralWidget? Or without any parent... Does it show up?

                    G Offline
                    G Offline
                    Gourmet
                    wrote on last edited by
                    #9

                    @Pl45m4 oops... parent() returns NULL. This is reason to investigate more...

                    G 1 Reply Last reply
                    1
                    • G Gourmet

                      @Pl45m4 oops... parent() returns NULL. This is reason to investigate more...

                      G Offline
                      G Offline
                      Gourmet
                      wrote on last edited by
                      #10

                      The solution is:

                      Dlg = new QWidget(QApplication::activeWindow());
                      
                      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