Own popup window
Solved
General and Desktop
-
Instead of comboBox, I want pull down window on button click.
In general, this window should have any content: for example multi-column, colored, etc.
For simple case - this will list of strings.
This window should be modal and automatic close if click for any point of application.
Will be best (but not necessary) not closing window if we open it, go to other application and back.
How do it? -
Sample solution code on gist:
gist Popup.cpp and .h -
I do
void SearchBar::adjustPopup() { if (!popup->isVisible()) { return; } QRect rect = button->geometry(); QPoint bottomLeft = this->mapToGlobal(rect.bottomLeft()); popup->setGeometry(QRect(bottomLeft, QSize(rect.width(),200))); } void SearchBar::resizeEvent(QResizeEvent *event) { QWidget::resizeEvent(event); adjustPopup(); } void SearchBar::moveEvent(QMoveEvent *event) { QWidget::moveEvent(event); adjustPopup(); } ............... popup = new QWidget(editor); popup->setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); connect(button,&QPushButton::clicked,[=](){ popup->setVisible(!popup->isVisible()); adjustPopup(); });
is problem: moveEvent is called on resize, but in my Mint Cinnamon, no moveEvent is produced during drag window.
try solution:
No moveEvent of my widget, but I must see moveEvent of Application -
Sample solution code on gist:
gist Popup.cpp and .h