October 16, 2011

amtm amtm
Lab Rat
6 posts

[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

  1. openVobDialog.setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint);
  2. 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.

5 replies

October 17, 2011

zither zither
Lab Rat
147 posts

How do u set make child as that dialog?

  1. QDialog *openVobDialog = new QDialog(this);
  2. openVobDialog->show();

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

October 17, 2011

amtm amtm
Lab Rat
6 posts

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.

October 17, 2011

amtm amtm
Lab Rat
6 posts

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.

October 17, 2011

amtm amtm
Lab Rat
6 posts

  1. OpenVobDialog::OpenVobDialog(QWidget *parent) :
  2.     QDialog(parent),
  3.     ui(new Ui::OpenVobDialog)
  4. {
  5.     ui->setupUi(this);
  6.     setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint);
  7. }

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:

  1. openVobDialog(this)

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

  1. void mainwindow::on_openVobButton_clicked()
  2. {
  3.     openVobDialog.show();
  4. }

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.

October 17, 2011

amtm amtm
Lab Rat
6 posts

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

  1. setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::Dialog);

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

 
  ‹‹ Qt example "Font sampler" Seg fault problem.      Cross-platform Preference Window Design ››

You must log in to post a reply. Not a member yet? Register here!