October 11, 2011

floatingWoods floatingWoods
Lab Rat
82 posts

QMenu or QToolBar with a common action slot?

 

Hello,

I managed having my QToolBar and QMenu work nicely in the Qt framework using the signal/slot mechanism (with QAction). However, since I am porting a rather large application from MFC where I used a common message handling routine for toolbar presses, menu selections, etc., I want to reuse it.
Practically this means that for any toolbutton press (or menu selection), the same slot should be called, and then inside that slot routine, I need to identify which button was pressed. A little bit something like:

  1. void aToolbarButtonWasPressed(int toolbarButtonID)
  2. { // This would be called when any toolbar button is pressed
  3.   if (toolbarButtonID==1)
  4.     clearScene();
  5.   if (toolbarButtonID==2)
  6.     openScene();
  7.   ...
  8. }

Any idea how I can achieve this?

2 replies

October 11, 2011

cincirin cincirin
Ant Farmer
444 posts

Look at QSignalMapper [doc.qt.nokia.com] class

October 11, 2011

floatingWoods floatingWoods
Lab Rat
82 posts

Excellent! Exactly what I was looking for, thanks a lot.

 
  ‹‹ Using TWAIN/SANE/CUPS with Qt.      [solved] Which mouse button caused the mousePressEvent in a graphics scene? ››

You must log in to post a reply. Not a member yet? Register here!