PDA

View Full Version : prevent selection in QComboBox.



hicpalm
20th May 2008, 12:11
hello,
how to select an element in a QComboBox programatically and prevent users from changing the selection, whithout setting the QComboBox desabled.
thanks

jpn
20th May 2008, 13:19
I'd say that preventing the selection from changing without disabling the combo box will just confuse your users. Adding a non-selectable item amongst other selectable items is a different story.

hicpalm
21st May 2008, 08:30
actually, the QComboBox is in a dialog box used in diffirent situations, and sometimes I would really give a unique choice to prevent errors.

jpn
21st May 2008, 08:53
It's hard to suggest anything concrete with this amount of background information, but have you considered any other UI components for solving the problem? You know, there are many ways to express "selection", perhaps combo box isn't the best possible choice in this case. Many times this is the case when one has to start customizing functionality of readily available widgets. In worst case the widget loses its intuitivity...

hicpalm
21st May 2008, 10:35
have you considered any other UI components for solving the problem? You know, there are many ways to express "selection"

the component here is constraint by the available dialog box space => QComboBox is suitable ?


this is the case when one has to start customizing functionality of readily available widgets

that's the case.
thanks.

louis_xx
21st May 2008, 12:06
You could set a custom model for your combo box. Then you can return the appropriate flags.

jpn
21st May 2008, 15:06
the component here is constraint by the available dialog box space => QComboBox is suitable ?
Ok, let's say it is. But combo box is also a well known and widely accepted UI component. People expect it to behave in a certain way. What's the problem with disabling it? That's the normal way of preventing selection... But making it semi-disabled in the sense that you can pop up the view but you still can't change the selection will most likely just confuse end-users, because that's not what people are used to.


You could set a custom model for your combo box. Then you can return the appropriate flags.
Sure it's possible. There's a solution somewhere on this forum. But the question is... is it really a sensible thing to do? :)