c++qtqcombobox

How to make QComboBox popup expand upwards?


I would like my QComboBox-derived class that's contained in a QGraphicsScene to expand its popup view upwards.

I tried this:

void MyComboBox::showPopup() {
    QComboBox::showPopup();
    QWidget *popup = this->findChild<QFrame*>(); 
    popup->move(popup->x(),popup->y()-this->height()-popup->height());
}

but there are two problems:


Solution

  • The solutions mentioned in How to make QComboBox popup upwards? work, but only after installing an event filter on view() in MyComboBox::setView:

    view()->installEventFilter(this)