Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Associating one menu with two QToolButton

Associating one menu with two QToolButton

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 5 Posters 622 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Ayush Gupta
    wrote on last edited by
    #1

    I have some menu with some QActions like

    QMenu test = new QMenu;
    QAction action1 = new QAction("test1",this);
    QAction action2 = new QAction("test2",this);

    Now adding QAction to menu
    test->addAction(action1);
    test->addAction(action2);

    Now to QPushButton
    QToolButton *button1 = new QToolButton(this);
    QToolButton *button2 = new QToolButton(this);

    attaching menu to QToolButton
    button1->setMenu(test);
    button2->setMenu(test);

    Now I need to connect the signal to QAction test1,test2.

    And do something according to the type of QPushButton. But how can I get to know the QPushButton type when I clicked on QAction since common menu is associated with two QToolButton.

    Is this possible?

    jsulmJ 1 Reply Last reply
    0
    • N Offline
      N Offline
      NotYourFan
      wrote on last edited by NotYourFan
      #2

      Hey,

      you can check the Signals form QAction here: QAction - Signals.
      Why you use QAction and not QPushButton?
      QPushButton have a signal "clicked" ...

      1 Reply Last reply
      0
      • A Ayush Gupta

        I have some menu with some QActions like

        QMenu test = new QMenu;
        QAction action1 = new QAction("test1",this);
        QAction action2 = new QAction("test2",this);

        Now adding QAction to menu
        test->addAction(action1);
        test->addAction(action2);

        Now to QPushButton
        QToolButton *button1 = new QToolButton(this);
        QToolButton *button2 = new QToolButton(this);

        attaching menu to QToolButton
        button1->setMenu(test);
        button2->setMenu(test);

        Now I need to connect the signal to QAction test1,test2.

        And do something according to the type of QPushButton. But how can I get to know the QPushButton type when I clicked on QAction since common menu is associated with two QToolButton.

        Is this possible?

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @ayush-gupta said in Associating one menu with two QToolButton:

        But how can I get to know the QPushButton type when I clicked on QAction

        I don't know what you mean with "type", but you can connect a lambda to the clicked() signal from the buttons and pass additional parameters to the lambda to differentiate the buttons.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • U Offline
          U Offline
          umod.47
          wrote on last edited by
          #4

          You can call sender() inside a slot to determine calling object and just compare, which button caused the slot to execute.

          Press ESCAPE to enter or ENTER to escape.
          Keyboard not found. Press F1 to continue.
          (c) BIOS

          J.HilkJ 1 Reply Last reply
          1
          • U umod.47

            You can call sender() inside a slot to determine calling object and just compare, which button caused the slot to execute.

            J.HilkJ Online
            J.HilkJ Online
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @umod-47 you can, but you shouldn't, let me quote the documentation

            0_1568705894317_13d69ae2-2a35-4555-adc3-be1bb907ed24-image.png


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            2

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved