PDA

View Full Version : locking the combobox



jayw710
1st April 2006, 00:30
Is there a way to lock the combobox, rather like disabling, but not changing colors. I want the box to appear active but not let the current item change. I don't care whether the listbox shows or not, I just don't want it to change. Is this possible?

Thanks!

Jay

wysota
1st April 2006, 01:01
You can remove all items from the combobox. It'll not be possible to change it then. Another way you could try is to connect the textChanged() signal (or activated() -- it should work the same) to a custom slot and make it change the item back to the one that should be selected. Although a normal behaviour is just to disable a widget that can't be used... Third way is to install an event filter on the combobox and filter out all mouse press events not letting them pass to the regular QComboBox mousePressEvent handler.

Protocol
1st April 2006, 01:28
Sure just "reset" the list box to what ever its original state after the user tries to make a change.

jayw710
1st April 2006, 16:45
I was hoping there was a simple function call, but these are both good solutions. Thanks!

Jay

SK
9th April 2006, 18:44
The way I did it is disabling it, but setting the "disabled" pallette properties of the combobox to the same as the "active" combobox.

high_flyer
10th May 2006, 17:12
@SK
Did you use setColorGroup() for that?
I have a similar problem and I tried the same thig but it doesnt work for me, am not sure why.
If I use setColorGroup() with QPalette::Inactive, and specify each color role, then set that pallete to my widget, when it gets disabled it just uses its normal disabled colors...
My actual problem is that I want to get rid of a text shadow in the disabled mode...
If you could post your code regarding this I would really appreciate it!


//current color group is active (this is in the constructor)
QPalette p = this->palette();
p.setColorGroup(QPalette::Disabled,p.windowText(), p.button(),p.light(),p.dark(),p.mid(),p.text(),p.b rightText(),p.base(),p.window());
setPalette(p);
Thanks.