Pergunta

I have a Combobox which has 3 items i.e. Item 1, Item 2 and item 3. I added these 3 items in .ui file and also added an image each for all using a resource file. Now when I am running the application, it shows the first item in combobox along with a image towards left. When i click on dropdown, I can see all the items along with images.

What I basically want to do is just display the image in the combobox and when user clicks on dropdown, it should show the image and text too.

Scenario: Items and images inside Combobox are added as follows:

Image 1 Item 1
Image 2 Item 2
Image 3 Item 3

When I run the app, it should display in combobox as

Image1

since first item gets displayed by default. I think it can be done when painting the current selection, QCombobox uses a re-implantation : void MyCombo::paintEvent(QPaintEvent *e) which is something I am not aware of.

Can anyone help me in this?? :)

How can I achieve it???

Foi útil?

Solução

You hould inherit a QComboBox and reimplement void QComboBox::showPopup () [virtual]
P.S. If you reimplement this function to show a custom pop-up, make sure you call hidePopup() to reset the internal state.
Second idea I have is to implement a model for combobox but i don't now exatly is there any roule for popup elements.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top