[Solved] QDialog set as child will not show



  • 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.



  • 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.



  • 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.



  • 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.



  • @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.



  • 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.



  • 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. : )


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.