PDA

View Full Version : Custom QComboBox



fruzzo
4th June 2012, 15:11
Hi,
I have to implement a custom combo box where the popup is something like a dialog which lists the combo items and has Ok/Cancel button to conform or reject the selected item...any suggestion how to easily implement it?
Alternatively, it's more easy to implement the same behaviour (Ok/Cancel button too) using a qpushbutton?

StrikeByte
4th June 2012, 15:49
It is probably possible to do but you will have 2 inherit the QComboBox and rewrite a few events (example on selection don't close but wait for ok button)
I think it is easyer to just add you're own view see QComboBox then explicitly the setView()

fruzzo
5th June 2012, 08:36
It is probably possible to do but you will have 2 inherit the QComboBox and rewrite a few events (example on selection don't close but wait for ok button)
I think it is easyer to just add you're own view see QComboBox then explicitly the setView()

Ok...I may be wrong, but doing as suggested by you I don't have a control of the selected item by Ok/cancel buttons...unfortunately as requirement I have to convert from a standard combo box to a drop-down list controlled in selection by ok/cancel buttons.

zgulser
5th June 2012, 08:45
Hi,

I'd rather deal with positioning than customizing QComboBox. I mean I created another little frame which owns a OK & Cancel buttons on it and set it's position when I open the combobox. When I close the combobox I'd just set it's visiblity to false.

fruzzo
5th June 2012, 08:53
Hi,

I'd rather deal with positioning than customizing QComboBox. I mean I created another little frame which owns a OK & Cancel buttons on it and set it's position when I open the combobox. When I close the combobox I'd just set it's visiblity to false.

In order to do this...have you reimplemented the QComboxBox::showPopup function? How do you associate the behaviour of your frame with the standard qcombox functions (i.e. activated/currentIndexChanged signals, currentIndex/setCurrentIndex functions)?

zgulser
5th June 2012, 09:04
Hi again,

You don't need to do extra work to associate them. When you press the OK or Cancel button, just check which item is checked/or not checked in the combobox and act accordingly.
(I assumed your items in the combobox are checkable since you want to reject or accept it through OK/Cancel buttons by the way)

If you wanted to point out this is not the correct way, I can agree with you but may take less time than struggling with subclassing.

StrikeByte
5th June 2012, 09:37
Ok...I may be wrong, but doing as suggested by you I don't have a control of the selected item by Ok/cancel buttons...unfortunately as requirement I have to convert from a standard combo box to a drop-down list controlled in selection by ok/cancel buttons.

You can add your own view (with an ok and cancel button) by using setView (i don't know if it works)

Maybe another option is to make an inheritance of a QLineEdit and add a widget. you can trigger the widget on a click event on the lineedit
i've made a small example of the lineedit type (the widget still opens in the wrong place, but its to get an idea) 7802

fruzzo
20th June 2012, 13:23
Well at the end I've customized my combobox pop showing the standard combobox list view in a dialog with Ok/Cancel like requested but I've another question...how can I resize my dialog to show all list view items without a vertical scolling?