Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make QComboBox popup upwards?

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

like image 825
user1319422 Avatar asked Apr 07 '12 18:04

user1319422


1 Answers

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!

like image 170
user1319422 Avatar answered Sep 19 '22 14:09

user1319422