how to connect QActions to SLOTS using qt designer
I have created a nice looking toolbar using qt Designer and populated it with some actions.
I tried to connect the actions to slots visually from qt designer by clicking edit> signals and slots. This DID NOT WORK because i could not find any QAction signals.Question.
Is there a way to connect the QAction SIGNAL(triggered()) to my slots within QT designer? Please help.
PS: I am currently being forced to connect throu开发者_开发问答gh code:QObject::connect(myAction, SIGNAL(triggered()),this, SLOT(myActionWasTriggered()))
but ia am lazy and i wish to connect using qt designer.
There's "Signal/Slot Editor" docked panel (Toggled with View->Signal/Slot Editor). You can connect your actions there. You may also need to add your custom slots via the "Change signals/slots" form context menu.
To save yourself some work, use the auto-connection feature (see QMetaObject::connectSlotsByName). Basically, all slots named with a specific pattern of on_objectName_signalName
will be auto-connected.
Look here in Docs Designer Connection Mode... How to autconnect in the designer
Use the "Action editor" panel. You can find it near "Signals & Slots editor".
If you have menu, Please name your actions object according to menus , Suppose you have:
File Edit View Tools Help
You have 5 menus bar,
So you'll have a set of action_x , x is a number.Please naming your x according to your menu.
more explaintion:
File = 1
Edit = 2
View = 3
Tools = 4
Help = 5
And suppose :
File---> Open ..Close
Edit---> find...replace
View---> ZoomIn ... ZoomOut
Tools--->calender... prefrences
help---> help... about
You have 5x2 = 10 , you have 10 action, please manage such as:
action_11 == File>Open
action_12 == File>close
action_21 == Edit>find
and so on..
Above type of managing make easy your coding .....
精彩评论