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

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!

Position of a Qt Combobox dropdown, The question was to make sure that the combobox always pops up in a given direction or position. Reply Quote 0. After countless hours trying to style a QComboBox, I'm stuck with the top and bottom margin where the items are inserted. I would like to either remove or apply a background-color to the popup menu top and bottom white spaces.

user1319422's solution isn't bad, but it has two problems.

  1. If your platform has GUI animation, the listbox will animate opening downwards, then is moved above the text box.
  2. If you disable combobox animation (or you don't have it), the call to QComboBox::showPopup() still makes the GUI element start to appear on the screen already. So, moving it there would cause it to flicker as it appears in the first place and moves to the next.

So, to address the first problem, I just switched off animation:

void MyComboBox::showPopup()
{
  bool oldAnimationEffects = qApp->isEffectEnabled(Qt::UI_AnimateCombo);
  qApp->setEffectEnabled(Qt::UI_AnimateCombo, false);

  QComboBox::showPopup();
  qApp->setEffectEnabled(Qt::UI_AnimateCombo, oldAnimationEffects);
}

Then, for the second problem, I moved the frame in the Show event:

bool MyComboBox::eventFilter(QObject *o, QEvent *e)
{
  bool handled = false;
  if (e->type() == QEvent::Show)
  {
    if (o == view())
    {
      QWidget *frame = findChild<QFrame*>(); 

      //For some reason, the frame's geometry is GLOBAL, not relative to the QComboBox!
      frame->move(frame->x(),
                  mapToGlobal(lineEdit()->geometry().topLeft()).y() - frame->height());
    }
  }
  /*else if other filters here*/

  if (!handled)
    handled = QComboBox::eventFilter(o, e);

  return handled;
}

how to check the popup direction in qcombobox, is there any way to check the popup direction of qcombobox . is it any way actually i have to show the popup in drop up even before qt adjust  Style QComboBox popup menu margin Qt 4. After countless hours trying to style a QComboBox, I'm stuck with the top and bottom margin where the items are inserted. I would like to either remove or apply a background-color to the popup menu top and bottom white spaces.

if you want to force popup to open above only when it is out of view you can do this:

void SteuerQComboBox::showPopup() {
    QComboBox::showPopup();
    QWidget *popup = this->findChild<QFrame*>(); 

    if((popup->y() + popup->height()) > this->window()->height())
        popup->move(popup->x(),popup->y()-this->height()-popup->height());
}

Resize Pop-up List of A Combo Box · ariya.io, It is possible to create a subclass of QComboBox and reuse its private members (​in header file qcombobox_p.h ), but this would have required a  Thanks but I guess I figured something. If the QCombobox is non editable it cannot be styled (i am not able to ) using QAbstractItemView. QComboBox::showPopup(); QWidget popup = this->findChild<QFrame>(); popup->move(popup->x(),popup->y()-this->height()-popup->height()); We can now position it anywhere we want.

qcombobox.cpp source code [qtbase/src/widgets/widgets , 499, // Some styles (Mac) have a margin at the top and bottom of the popup. 571, }. 572. 573, /*!. 574, Sets the item view to be used for the combobox popup. 575, */ 945, in a way that takes up the minimum amount of screen space. 946. and Then create a function that will open the dialog: def open_dialog(self): dialog = QtWidgets.QDialog() dialog.ui = Form() dialog.ui.setupUi(dialog) dialog.exec_() dialog.show() which I will connect to your first button: self.firstbutton.clicked.connect(self.open_dialog) In the dialog.py, you can get rid of these lines:

QComboBox, QComboBox widget is a combined button and popup list. A combobox is a selection widget that displays the current item, and can pop up a list of selectable items. QComboBox also provides functions to set and get item data (e.g., PySide. The problem is, even though the color rectangle displays well on the button for the currently selected item: It's displaying tiny for the items on the popup list: It seems that the pixmap itself is always scaled down to a width of about 15px, no matter what size I choose for setIconSize.

QComboBox Class Reference, The QComboBox widget is a combined button and popup list. A combobox is a selection widget that displays the current item, and can pop up This enum specifies what the QComboBox should do when a new string is entered by the user. This will also reveal a side-issue with setting a parent, in that every call of buildExamplePopup will create a new widget (i.e. the previous widget doesn't get destroyed, because Qt still has a reference to it). So it's good practice to use popup.setAttribute(Qt.WA_DeleteOnClose) to avoid that issue. – ekhumoro Mar 5 '16 at 19:28

Comments
  • Not a bad solution, but it animates downward and then moves up.