How to make QComboBox popup upwards?

user1319422 picture user1319422 · Apr 7, 2012 · Viewed 7.8k times · Source

my QComboBox-derived class lives in a QGraphicsScene at the bottom end of the (visible) screen - but it pops up downwards, thus out of view.

(How) is it possible to force the popup to open above the widget?

I've tried re-implementing showPopup like this:

void MyComboBox::showPopup()
{
     QAbstractItemView *popupView = view();
     popupView->move(0,-100);
     //popupView->window->move(0,-100);
     QComboBox::showPopup();
}

The result is, that the content seems to be shifted, but not the underlying popup object. I think it might be possible to find a solution with styles as indicated in this article, but I can't find any Styles control that might be helpful here. I am rather new to C++ as well as Qt, so I might be missing something obvious.

I'd appreciate any help on this matter!

Best regards,

Sebastian

Answer

user1319422 picture user1319422 · Apr 9, 2012

With the information found here, I was able to get it done this way:

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

Note that it's crucially important to call the base classes "showPopup" first.

Thanks to everybody who was reading my question and thinking about it!