PDA

View Full Version : Disabling options in a combobox



the goat boy
18th July 2008, 10:25
Hi there

I am pretty new to QT, so please bear with me on this. I have had a scan of this forum, but as yet can't see a solution.

Basically I have two combo boxes on an interface, each controlling two separate threads for serial port access.

What I want to be able to do is select one box, and this in turn will disable that option in a different combobox.

for example I have the following ports selectable:

ttyS0
ttyS1
ttyS2
ttyS3
ttyUSB0

so if i select ttyS0 in one combo box, i want that option disabled in the second combo box to stop that port being activated by the other program. and vice versa if an option is selected in combo box 2, it needs to be disabled in combobox 1.

is there a way to do this?

so far the only way i can see is to use remove the index from the list. is this the best way to do this??

thanks in advance

Raccoon29
18th July 2008, 10:37
I think that removing the row is the more safe and easy way to achieve it.
In QComboBox it seems that you add strings and data, no items like in QTableWidget for example, so you can't say to one of them setEnabled(false) for example.
I don't know more sophisticated methods, but to simulate a not enabled row, you could work around with (or overload) the QComboBox::highlight(int index) signal, in order to deny to the user to highlight the disabled row...but seems so messy...

luf
18th July 2008, 21:04
Create a QList that has the all the available options in a struct including availability/or if they are used somewhere, then load the options off that one removing any options that are used somewhere. Connect a signal from the QList to each of the combobox'es so they are updated each time the list gets updated.

Depending on what you need the data for later, you might consider model/view or QSettings...

jpn
21st July 2008, 18:37
QComboBox works on top of a model so using QStandardItemModel might be the easiest way to go. You can easily enable/disable QStandardItems.