48 static constexpr int max_popup_height = 250;
51 : QListView(combo), combo_(combo) {}
53 QSize sizeHint()
const override {
54 const auto s = QListView::sizeHint();
55 return { s.width(), std::min(s.height(), max_popup_height) };
59 void showEvent(QShowEvent* event)
override {
60 QListView::showEvent(event);
63 QTimer::singleShot(0,
this, [
this]() {
64 QWidget* popup = parentWidget();
65 if (!popup || !combo_ || popup->height() <= max_popup_height)
69 const QPoint comboPos = combo_->mapToGlobal(QPoint(0, 0));
70 const QRect comboRect(comboPos, combo_->size());
73 const QScreen* screen = QApplication::screenAt(comboPos);
74 const QRect screenRect = screen
75 ? screen->availableGeometry()
76 : QRect(0, 0, 9999, 9999);
80 popup->resize(popup->width(), max_popup_height);
81 int y = comboRect.bottom() + 1;
82 if (y + max_popup_height > screenRect.bottom())
83 y = comboRect.top() - max_popup_height;
84 popup->move(popup->x(), y);
89 QPointer<QComboBox> combo_;