PDA

View Full Version : Drawing of Combobox with QStyleOptionComboBox problems



michael.
11th October 2011, 14:41
I'm attempting to draw a combobox in my QStyledItemDelegate-based delegate. I want the user to know that the item is a combobox but the view can contain thousands of items, so opening a persistent Editor for each item is not an option.
My paint function looks like this:


void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QStyleOptionComboBox box;

box.rect = option.rect;
box.currentText = "test";

QApplication::style()->drawComplexControl(QStyle::CC_ComboBox, &box, painter, 0);
QApplication::style()->drawControl(QStyle::CE_ComboBoxLabel, &box, painter, 0);
}

Everything gets drawn correctly except the downward facing arrow on the combobox. It always gets drawn on the correct x coordinate but the y coordinate seems to be the one one would use to paint the control for the first item:
6974

The option.rect passed in contains the correct coordinates, and drawComplexControl is drawing outside of that rect.
So my question is where does Qt get the coordinates for the arrow from? How can it be outside of the style options rect?