0

I have QDialog which is a child of mainWindow. My problem is I can't use setWindowsFlag when set parent for the dialog: the dialog sticks to the top left of MainWindow and is transparent .The code look like this:

mainWindow::MainWindow(QWidget* parent): QMainWindow(parent)
{
   this->setWindowsFlags(Qt::FramelessWindowHint);
   mpConfirmDialog = new ConfirmDialog();//mpConfirmDialog is a pointer and member of MainWindow
   mpConfirmDialog->setParent(ui->centralWidget) ;//pass ui->centralWidget in constructor cause crash when exit????
   mpConfirmDialog->hide();
}

In constructor of ConfirmDialog:

ConfirmDialog::ConfirmDialog(QWidget* parent){
    this->setWindowsFlags(Qt::FramelessWindowHint);// only effective if comment  mpConfirmDialog->setParent(ui->centralWidget) in MainWindow
}

Any ideas are appreciated.

Tiana987642
  • 696
  • 2
  • 10
  • 28

1 Answers1

0

There is some inconsistency between OSes but we should keep in mind that the parent class constructor very likely sets some flags already and the flag add logic is bitwise OR. We can try to ensure we don't loose those flags.

this->setWindowFlags(this->windowFlags() | Qt::FramelessWindowHint);

This may help to degree but of course I don't have your environment and entire code sample to prove.

Alexander V
  • 8,351
  • 4
  • 38
  • 47
  • Thanks , but it ain't work. BTW, I figured it out: use `mpConfirmDialog->setWindowFlags(Qt::FramelessWindowHint)` right after init the pointer. I feel it quite weird. – Tiana987642 May 26 '15 at 14:55