Results 1 to 15 of 15

Thread: Detect Button Press / Release in toolbar

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Detect Button Press / Release in toolbar

    A QToolButton is a QAbstractButton, it has a QAbstractButton::pressed() and QAbstractButton::released() signal.

    Cheers,
    _

  2. #2
    Join Date
    Jul 2014
    Posts
    8
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11
    Thanks
    2

    Default Re: Detect Button Press / Release in toolbar

    Hi Guys and thanks for your replies...

    I have made some progress with the event filter...

    If I do this in mainwindow.cpp

    FilterObject FO;

    ui->mainToolBar->installEventFilter(&FO);

    and then in FilterObject

    bool FilterObject::eventFilter(QObject *object, QEvent *event)
    {
    if (event->type() == QEvent::MouseButtonPress) {
    qDebug() << "Mouse Press On Toolbar";
    return true;
    }

    return false;
    }

    I can detect the mouse press on the toolbar which is great.

    However when I try to detect the mouse pressed from a button / action on the toolbar it no longer works

    I replace ui->mainToolBar->installEventFilter(&FO); with ui->actionDoWork->installEventFilter(&FO);

    The action DoWork is a button generated by the Action Editor.

    So basically it works to detect mouse events on the toolbar but not from an action button on the toolbar.

    What I really need is to read the mouse events from the buttons on the toolbar.

    Again, thanks and any ideas / hints are welcome.

    Regards,
    Louis

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Detect Button Press / Release in toolbar

    Why do you use an event filter?
    What is the reason you are not using the signals of the button?

    Cheers,
    _

  4. The following user says thank you to anda_skoa for this useful post:

    irish_guy@hotmail.com (10th September 2015)

  5. #4
    Join Date
    Jul 2014
    Posts
    8
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11
    Thanks
    2

    Default Re: Detect Button Press / Release in toolbar

    Thanks Anda,

    I used the event filter because I was unable to figure out how to use these signals of the button on a toolbar.

    I can use the signals from a normal push button but I can't understand how to get the same signals from the toolbar buttons.

    Is there any example of using the QAbstractButton in this way or a similar way?

    I am new to this so sorry if it is obvious....

    Thanks Again,
    Louis

  6. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Detect Button Press / Release in toolbar

    Quote Originally Posted by irish_guy@hotmail.com View Post
    I can use the signals from a normal push button but I can't understand how to get the same signals from the toolbar buttons.
    There is no difference. The signal/slot mechanism works the same way for all QObject subclasses

    With SIGNAL/SLOT macros:
    Qt Code:
    1. connect(pointerToToolButton, SIGNAL(pressed()), pointerToReceiver, SLOT(someSlotNameHandlingPress()));
    To copy to clipboard, switch view to plain text mode 
    The circumstance that the button is on a toolbar doesn't change anything, connect() doesn't even care that the sender is a QWidget derived class.

    Cheers,
    _

  7. #6
    Join Date
    Jul 2014
    Posts
    8
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11
    Thanks
    2

    Default Re: Detect Button Press / Release in toolbar

    Thanks again & Almost there I think...

    When I try to connect the signals and slots... I get a run time message that there is No such Signal QAction:ressed()

    connect(ui->actionZoom_In, SIGNAL(pressed()), this, SLOT(MousePress()));

    QObject::connect: No such signal QAction:ressed() in ../CameraControlGUI/mainwindow.cpp:66
    QObject::connect: (sender name: 'actionZoom_In')
    QObject::connect: (receiver name: 'MainWindow')

    When I connect to the 'triggered signal'

    connect(ui->actionZoom_In, SIGNAL(triggered()), this, SLOT(MousePress()));

    it works fine but I really need pressed and released...

    Regards
    Louis

  8. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Detect Button Press / Release in toolbar

    Ah, yes, I should have written QToolButton, not QAction.

    Oh, wait, I did.

    Cheers,
    _

Similar Threads

  1. how to capture the F1 - key press/release event
    By sajis997 in forum Qt Quick
    Replies: 1
    Last Post: 6th January 2015, 23:25
  2. Mouse Press/Release Events
    By Vivek1982 in forum Newbie
    Replies: 27
    Last Post: 22nd August 2014, 14:17
  3. Want to detect keyboard key press other than modifier keys
    By Rajesh.Rathod in forum Qt Programming
    Replies: 3
    Last Post: 25th October 2013, 08:19
  4. Replies: 6
    Last Post: 21st August 2010, 22:09
  5. How catch key press and key release for entire application
    By hubbobubbo in forum Qt Programming
    Replies: 4
    Last Post: 1st June 2010, 21:53

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.