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. Question about QAction
Qt 6.11 is out! See what's new in the release blog

Question about QAction

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 405 Views 3 Watching
  • 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.
  • R Offline
    R Offline
    rock37
    wrote on last edited by
    #1

    Hey folks,
    i have the following code:

     QToolButton *_log_type_button = new QToolButton(this);
      _log_type_button->setIcon(QIcon(":/res/images/debug_log_messages.png"));
      _log_type_button->setCheckable(true);
      _log_type_button->setPopupMode(QToolButton::InstantPopup);
      _log_type_button->setMaximumSize(36,36);
      std::cout << "QToolButton created" << std::endl;
    
      auto a1 { new QAction("Show log messages") };
      a1->setCheckable(true);
      a1->setIcon(QIcon(":/res/images/debug_log_messages.png"));
    //  a1->setChecked(Application::settings().value("LogMessages", true).toBool());
    
      auto a2 { new QAction("Show log warnings") };
      a2->setCheckable(true);
      a2->setIcon(QIcon(":/res/images/debug_log_warnings.png"));
    //  a2->setChecked(Application::settings().value("LogWarnings", true).toBool());
    
      auto a3 { new QAction("Show log errors") };
      a3->setCheckable(true);
      a3->setIcon(QIcon(":/res/images/debug_log_errors.png"));
     // a3->setChecked(Application::settings().value("LogErrors", true).toBool());
      std::cout << "Actions created.. " << std::endl;
    
      _log_type_button->addAction(a1);
      _log_type_button->addAction(a2);
      _log_type_button->addAction(a3);
    

    now my question is how can i make a function call when one of the icons is clicked.

    best regards,
    stuv

    M 1 Reply Last reply
    0
    • R rock37

      Hey folks,
      i have the following code:

       QToolButton *_log_type_button = new QToolButton(this);
        _log_type_button->setIcon(QIcon(":/res/images/debug_log_messages.png"));
        _log_type_button->setCheckable(true);
        _log_type_button->setPopupMode(QToolButton::InstantPopup);
        _log_type_button->setMaximumSize(36,36);
        std::cout << "QToolButton created" << std::endl;
      
        auto a1 { new QAction("Show log messages") };
        a1->setCheckable(true);
        a1->setIcon(QIcon(":/res/images/debug_log_messages.png"));
      //  a1->setChecked(Application::settings().value("LogMessages", true).toBool());
      
        auto a2 { new QAction("Show log warnings") };
        a2->setCheckable(true);
        a2->setIcon(QIcon(":/res/images/debug_log_warnings.png"));
      //  a2->setChecked(Application::settings().value("LogWarnings", true).toBool());
      
        auto a3 { new QAction("Show log errors") };
        a3->setCheckable(true);
        a3->setIcon(QIcon(":/res/images/debug_log_errors.png"));
       // a3->setChecked(Application::settings().value("LogErrors", true).toBool());
        std::cout << "Actions created.. " << std::endl;
      
        _log_type_button->addAction(a1);
        _log_type_button->addAction(a2);
        _log_type_button->addAction(a3);
      

      now my question is how can i make a function call when one of the icons is clicked.

      best regards,
      stuv

      M Offline
      M Offline
      mpergand
      wrote on last edited by mpergand
      #2

      @rock37
      Look at the link I mentioned in your previous post, you will find:

      void MainWindow::createActions(){
          alignLeftAction = new QAction("Align left", this);
          alignCenterAction = new QAction("Align center", this);
          alignRightAction = new QAction("Align right", this);
      
          alignLeftAction->setIcon(QIcon(":/icons/alignLeft.png"));
          alignCenterAction->setIcon(QIcon(":/icons/alignCenter.png"));
          alignRightAction->setIcon(QIcon(":/icons/alignRight.png"));
      
          QObject::connect(alignLeftAction, SIGNAL(triggered()), 
                                      this, SLOT(alignLeft()));
          QObject::connect(alignCenterAction, SIGNAL(triggered()), 
                                        this, SLOT(alignCenter()));
          QObject::connect(alignRightAction, SIGNAL(triggered()), 
                                        this, SLOT(alignRight()));
      }
      
      Pl45m4P 1 Reply Last reply
      1
      • M mpergand

        @rock37
        Look at the link I mentioned in your previous post, you will find:

        void MainWindow::createActions(){
            alignLeftAction = new QAction("Align left", this);
            alignCenterAction = new QAction("Align center", this);
            alignRightAction = new QAction("Align right", this);
        
            alignLeftAction->setIcon(QIcon(":/icons/alignLeft.png"));
            alignCenterAction->setIcon(QIcon(":/icons/alignCenter.png"));
            alignRightAction->setIcon(QIcon(":/icons/alignRight.png"));
        
            QObject::connect(alignLeftAction, SIGNAL(triggered()), 
                                        this, SLOT(alignLeft()));
            QObject::connect(alignCenterAction, SIGNAL(triggered()), 
                                          this, SLOT(alignCenter()));
            QObject::connect(alignRightAction, SIGNAL(triggered()), 
                                          this, SLOT(alignRight()));
        }
        
        Pl45m4P Online
        Pl45m4P Online
        Pl45m4
        wrote on last edited by
        #3

        @mpergand

        The SIGNAL - SLOT syntax will never die, as long as it's being taught to new Qt users 😅🤣


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        1 Reply Last reply
        1

        • Login

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