Controlling the direction of a QComboBox's drop-down menu
-
Is there any way to choose if the drop-down menu should appear bellow or above the QComboBox?
I have a QComboBox at the bottom of a page and when I click it the menu drops below the box and only shows one item and a scroll-bar. Would like it to appear above the box instead.
Using QT 3.3.6
-
Not that I'm aware of. The public API provides no means for this.
-
Also, 3.3.6 is an extremely old Qt version. If circumstances allow, upgrading to something more modern would be a benefit. (Though, if it's legacy code, I understand the situation too!)
-
While I generally agree with the updating advice, I think that for this case, it would not help. Even in 4.7.3 I know of no way to force this behavior.
-
One solution to explore is :
- creating a subclass of QComboBox ;
- reimplementing the QComboBox::showPopup() function.
However, if you look at showPopup source-code, you'll see that they use a lot of private stuff (pimpl), so you won't have access to it in your class, since it's private and not protected.
The way to go would then be to move the view used to render the popup. You can access it by calling QComboBox::view(). It should then give something like :
@
void MyComboBox::showPopup()
{
QAbstractItemView *popupView = view();
popupView->move(...);QComboBox::showPopup();
}
@ -
unfortunately showPopup() and view() is not available i version 3.3.6 and updating to a new version of Qt is not an option
[quote author="octal" date="1314262343"]One solution to explore is :
- creating a subclass of QComboBox ;
- reimplementing the QComboBox::showPopup() function.
However, if you look at showPopup source-code, you'll see that they use a lot of private stuff (pimpl), so you won't have access to it in your class, since it's private and not protected.
The way to go would then be to move the view used to render the popup. You can access it by calling QComboBox::view(). It should then give something like :
@
void MyComboBox::showPopup()
{
QAbstractItemView *popupView = view();
popupView->move(...);QComboBox::showPopup();
}
@[/quote] -
Indeed, your Qt version might be an issue.
However, since I've never used Qt 3.x, I can't help you more. Good luck for finding a solution.
-
[quote author="buggex" date="1314270208"]unfortunately showPopup() and view() is not available i version 3.3.6 and updating to a new version of Qt is not an option
[/quote]
No, but according to the docs, you do have a virtual popup() method and a method that returns a listBox() method. That is basically the Qt 3 version of showPopup() and view().
-
will try solving my problem another way, thanks for the help
-
AFAIK the combobox shows the popup by default below the box, if it fits there. If not, it tries to position it upwards. This is done automatically...