Reputation: 11
I am having trouble adding action to my main toolbar in a tab widget. The buttons on the toolbar are: Save,Print,Send,Clear & Exit. I have been able to add action to clear and exit via the action editor but cannot figure out how to get the open, print and send to work. The main data fields on my widget are Line edits, comboboxes and spinboxes. Any help would be awesome! Thank you!
Upvotes: 1
Views: 6323
Reputation: 73
To associate a button with some action, you should do the following:
connect(ui->saveTool, SIGNAL(clicked()), this, SLOT(save()));
Where ui->saveTool
is your button on the toolbar and save()
a function you want to call pressing the button.
If you also want to use QAction
for accomplishing this, you should just simply create the action, set a hot-key for it and connect it to the function:
QAction saveAct = new QAction("Save", this);
saveAct->setShortcut("Ctrl+S");
connect(saveAct, SIGNAL(triggered()), this, SLOT(save()));
The other way to set functions for a toolbar is via designer: you need to click the right mouse key on the toolButton, get to the slots it supports and use a slot clicked()
. You will see the on_saveTool_clicked()
slot created, where you can write your code.
Upvotes: 2