Reputation: 1405
I have a main window for my application, and when a button is clicked, I have a slot to open a popup window:
void MainWindow::slotContinue()
{
PopupWindow *pop = new PopupWindow(this);
pop->show();
}
I pass this
to the popup so that a button in the popup window can connect to the main window's slot.
PopupWindow::PopupWindow(QWidget *parent) :
QWidget(parent)
{
setFixedSize(360, 100);
contButton = new QPushButton("Continue", this);
contButton->setGeometry(140, 60, 80, 30);
connect(contButton, SIGNAL(clicked()), parent, SLOT(slotCalibrate()));
connect(contButton, SIGNAL(clicked()), this, SLOT(close()));
}
The popup window never appears. The continue button appears, but is part of the main window. The functionality of the button is fine. Upon clicking it, slotCalibrate()
is successfully called and the button disappears, but I can't figure out why it is a child of what is supposed to be its grandparent.
If I don't pass this
to the popup constructor the window appears but I can't connect the continue button to slotCalibrate()
.
Upvotes: 2
Views: 94
Reputation: 7044
PopupWindow
class inherits from QWidget
, so it's not a window by default if it has a parent, it will be part of that parent, you need to set it to be a window:
void MainWindow::slotContinue()
{
PopupWindow *pop = new PopupWindow(this);
pop->setWindowFlags(Qt::Window);
pop->show();
}
Upvotes: 2