1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-02 10:24:11 +01:00

Set drop down width using list box size hint as necessary

This commit is contained in:
David Willis 2011-11-05 02:04:34 +00:00
parent bcf200bc4f
commit 3dd708a564

View File

@ -55,6 +55,7 @@
#include <QtGui/QStyleOption>
#include <QtGui/QToolBar>
#include <QtGui/QToolButton>
#include <QtGui/QAbstractItemView>
// We define a currently unused state for indicating animations
#define State_Animating 0x00000040
@ -217,7 +218,29 @@ QRect ManhattanStyle::subControlRect(ComplexControl control, const QStyleOptionC
SubControl subControl, const QWidget *widget) const
{
QRect rect;
rect = d->style->subControlRect(control, option, subControl, widget);
// Need to check for Mac style and use the default behaviour for that
if(control == CC_ComboBox && subControl == SC_ComboBoxListBoxPopup)
{
const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option);
const QComboBox* combo = qobject_cast<const QComboBox*>(widget);
QRect comboRect = cb->rect;
int newWidth = combo->view()->sizeHintForColumn(0);
if(newWidth > comboRect.width())
{
// Set new rectangle, only width matters, list height is set by
// combination of number of combo box items and setMaxVisibleItems
rect.setRect(comboRect.x(), comboRect.y(), newWidth, comboRect.height());
rect = visualRect(cb->direction, cb->rect, rect);
}
else
{
rect = d->style->subControlRect(control, option, subControl, widget);
}
}
else
{
rect = d->style->subControlRect(control, option, subControl, widget);
}
return rect;
}