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