Reputation: 73
I'm trying to place a popup window at the bottom right corner of the main window .It should be visible there even the main window got resized/expanded.
How can I do that in Qt 5.9 (in C++)?
Upvotes: 0
Views: 1818
Reputation: 244003
The important task in your question is to move the popup when the QMainWindow is resized or moved, for this we must override the resizeEvent
and moveEvent
method. the following code shows how to do it:
void MainWindow::movePopUp()
{
QPoint p = mapToGlobal(QPoint(size().width(), size().height())) -
QPoint(popup->size().width(), popup->size().height());
popup->move(p);
}
void MainWindow::resizeEvent(QResizeEvent *event)
{
movePopUp();
QMainWindow::resizeEvent(event);
}
void MainWindow::moveEvent(QMoveEvent *event)
{
movePopUp();
QMainWindow::moveEvent(event);
}
Output:
The complete example is here
Upvotes: 2