PDA

View Full Version : Adding Icons to Combobox Items such that Icons are visible at the Right Side



krishnakishoreraju
3rd April 2013, 16:57
I am working on an application in which I need to show the List of Program Names and corresponding Icons in a Combobox Popup Menu.

I tried following things:

a. Created the Custom Widget deriving from QCombobox b. ReImplemented the showPopup() function as follows

void CMyComboBox::showPopup()
{
QComboBox::showPopup();
mp_Popup = this->findChild<QFrame *>();
mp_Popup->move( mp_Popup->x(), mp_Popup->y() - this->height() - mp_Popup->height() );
}

b. Adding Items to Combobox QString Name = "XYZ"; QIcon icon("Sample.png");

myComboBox->insertItem(0, icon, Name);

Question is: When I insert using above method, it inserts the Icon at the left side(i.e.., Icon followed by Name) . How do I make the Icons to come at the Right Side(i.e.., Name First then the Icon)

Regards Santhosh

krishnakishoreraju
8th April 2013, 06:54
Any answers from this forum for this query.

wysota
8th April 2013, 07:40
For the icon to appear on the right side you need to provide a custom item delegate that will paint the decoration on the right side of the text instead of the default left side.