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 set as child will not show
Forum Update on Monday, May 27th 2025

[Solved] QDialog set as child will not show

Scheduled Pinned Locked Moved General and Desktop
9 Posts 5 Posters 16.2k 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.
  • A Offline
    A Offline
    amtm
    wrote on last edited by
    #1

    If I construct a QDialog as a child of my main window and I also call setWindowFlags on the dialog it will not become visible when I call show(). Is there something I am doing wrong? The code is just

    @openVobDialog.setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint);
    openVobDialog.show();@

    Now if I set the dialog back as it's own top-level window it will show just fine, but I want it to be a child dialog so it doesn't add another entry to the taskbar and it will auto-center in the middle of the mainwindow.

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      zither
      wrote on last edited by
      #2

      How do u set make child as that dialog?

      @QDialog *openVobDialog = new QDialog(this);
      openVobDialog->show();@

      It should works. Could you show me some more codes.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        amtm
        wrote on last edited by
        #3

        I found out the problem. I was constructing the openVobDialog in the initialization list of my mainwindow's constructor as openVobDialog(this) instead of openVobDialog(parent). Once I switched it it works fine now.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          amtm
          wrote on last edited by
          #4

          Ok, so that didn't really help. All that did was once again make the dialog have its own taskbar entry which is not what I want. This makes no sense. And yes, what you specify does work but I want to have the dialog only have a title and no ? or close buttons which the setWindowFlags call is for getting. I know from reading the docs that the setWindowFlags call makes the window hidden but the call to the dialog's show method doesn't seem to have any effect.

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

            @OpenVobDialog::OpenVobDialog(QWidget *parent) :
            QDialog(parent),
            ui(new Ui::OpenVobDialog)
            {
            ui->setupUi(this);
            setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint);
            }@

            That's the constructor of the OpenVobDialog class since I moved the setWindowFlags call into the constructor. In the initialization list of the qmainwindow class I added this:

            @openVobDialog(this)@

            in the list to construct the object. Also when the button is clicked it calls into this slot:

            @void mainwindow::on_openVobButton_clicked()
            {
            openVobDialog.show();
            }@

            I've even added lines that pops up a message box after the show call that provides info on the isHidden and isVisible state and they both say true even after the show call. For some reason it is not changing the isHidden state.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              amtm
              wrote on last edited by
              #6

              Ok, I have now found the solution. I changed the setWindowFlags call to:

              @setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::Dialog);@

              I hadn't realized it also needed the Qt::Dialog part as well.

              CybeXC 1 Reply Last reply
              1
              • Z Offline
                Z Offline
                zeFree
                wrote on last edited by
                #7

                Note:
                I know that it is (perhaps very) late to add into this discussion but I just want to add my two cents for the posterity.

                Thanks for the vital discussion. It helped me a lot. For me, putting in only the "Qt:Dialog" flag, did the trick.

                I was using:
                @dialog.setParent(this);@

                to set the QMainWindow as dialog's parent which, as described in the document was "setting the parent of the dialog to parent, but was also resetting its window flags, and was moving it to position (0, 0) in the QMainWindow."

                After using:
                @dialog.setParent(this, Qt::Dialog);@

                it was popping-up in the center of the QMainWindow - exactly as I wanted it to. : )

                1 Reply Last reply
                0
                • A amtm

                  Ok, I have now found the solution. I changed the setWindowFlags call to:

                  @setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::Dialog);@

                  I hadn't realized it also needed the Qt::Dialog part as well.

                  CybeXC Offline
                  CybeXC Offline
                  CybeX
                  wrote on last edited by
                  #8

                  @amtm said in [Solved] QDialog set as child will not show:

                  Ok, I have now found the solution. I changed the setWindowFlags call to:

                  @setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::Dialog);@

                  I hadn't realized it also needed the Qt::Dialog part as well.

                  Had a similar issue while developing in Windows 10. Sometimes my Dialogs won't open, other times they will. Appears compeletely random.

                  I added this to my QDialog class after ui->setupUi(this); and it works like a charm

                  setWindowFlags(Qt::Dialog);
                  

                  Thanks for the solution

                  JonBJ 1 Reply Last reply
                  0
                  • CybeXC CybeX

                    @amtm said in [Solved] QDialog set as child will not show:

                    Ok, I have now found the solution. I changed the setWindowFlags call to:

                    @setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::Dialog);@

                    I hadn't realized it also needed the Qt::Dialog part as well.

                    Had a similar issue while developing in Windows 10. Sometimes my Dialogs won't open, other times they will. Appears compeletely random.

                    I added this to my QDialog class after ui->setupUi(this); and it works like a charm

                    setWindowFlags(Qt::Dialog);
                    

                    Thanks for the solution

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #9

                    @CybeX
                    If you say you need to do that (I have not found that one does, but let's assume), then for others reading this I would have though a safer, generic solution of

                    setWindowFlags(Qt::Dialog | windowFlags());
                    

                    or

                    setWindowFlag(Qt::Dialog, true)
                    

                    would be preferable.

                    1 Reply Last reply
                    2

                    • Login

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