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