PDA

View Full Version : ComboBox with lines



Braunstein
5th March 2010, 15:41
Hello,

I would like to create a ComboBox for selecting different line styles. I triedto to use a delegate that uses the paint function to draw these lines. This works well for the popup list, But i want, that the user can select one line style and this line should be shown in the editor field. But here i see nothing. The delegate seems to work only in the popup list.
How can i do this?

Best regards
Heiko

Braunstein
16th March 2010, 08:12
Hello,

Now i found a solution. You have to derive a new ComboBox from QComboBox. In this you must overload the paintEvent. This should look like this.

void MyComboBox::paintEvent(QPaintEvent * event)
{
QStylePainter painter(this);

// draw the combobox frame, focusrect and selected etc.
QStyleOptionComboBox opt;
initStyleOption(&opt);
painter.drawComplexControl(QStyle::CC_ComboBox, opt);

// draw something in the edit
QRect rect = painter.style()->subControlRect(QStyle::CC_ComboBox, &opt, QStyle::SC_ComboBoxEditField, this);
// now you have the rect of the lineEdit and a painter and you can paint wathever you want.
}