I'm a bit stucked with creating drop-down button based on QAction
placed in QToolBar
I have an XML file with following data:
<cfg>
<fields>
<group name="First fields">
<field>filed1</field>
<field>filed2</field>
<field>filed3</field>
</group>
<group name="Second fields">
<field>filed4</field>
<field>filed5</field>
<field>filed6</field>
... etc ...
</group>
</fields>
<button name="MyButton1" />
<button name="MyButton2 />
... etc ...
</cfg>
NB: I don't know how much field groups will be, as well as I don't know how much button will be.
So, first of all, I parse following xml-file and extract needed data.
For each button
I create its own QAction
and add it to the existing toolbar.
Later, I create QMenu
for each button and fill it with QAction
s for each group and field. I have QAction
for First fields
, field1
, field2
, etc...
Then, for each button
I use setMenu
method and add created menus there.
If I launch my app I can see my buttons in toolbar with drop-down menus and they looks like I expected.
The problem here is that I need to add some functionality to this buttons.
I'd like to allow user to check them (I use setCheckable
for all QActions
) and uncheck. When user checks actions with group name all fields related to this group become checked and so on.
As I don't know how much buttons and fields I will have on startup it become difficult to work with signals and slots.
It forces me to use QMap
to store all addresses of created QAction
, when the signals from this fields being emited, then using find method to look for actions that emited it and only them perform needed action.
The question is: is there a better way to achieve my goal or I should continue using this approach?