SilverWolfe
SilverWolfe

Reputation: 85

Populate QComboBox with QEnums

I've looked in multiple places and cannot seem to find anything to work for my purpose. I have this QComboBox that constantly changes (And could change after the program is completely finished). To make it easier I made an Enum list for switch statements

public:
   enum Race{
         Race1,
         Race2,
         ect
   }

The combo is filled with the same elements. However, I want to make it even easier. So instead of changing the Combobox and changing the enum list, is there a way where all i have to do is add a new "race" to the enum list, that it will populate the combobox, so all i would have to do is a switch statement to handle new race?

Additional info: I'm willing to put the enum list into a qstringlist. I have Q_ENUMS (Race) set

Upvotes: 0

Views: 1094

Answers (1)

Silicomancer
Silicomancer

Reputation: 9176

Using Q_ENUMS will give you a way to iterate over your enum and add their enumerands to the combobox in a loop. However it will not give you the possibility to add a related GUI text for each enumerand. The enumerand name like it is written in your source code will be available only. Maybe your code side name is not what you want to see in your GUI as a text.

Remember that you can add any kind of QVariant supported user values to a combobox while you populate it with text strings... so you do not need to maintain an enumeration if there is some other kind key you can use instead.

Upvotes: 1

Related Questions