Signal difference between clicked, pressed, released, toggled, and triggered of QAbstractButton

Original link: https://ifmet.cn/posts/c554435b/

Brief Description: Explain the difference between the following signals

  • QAbstractButton: ①clicked ② pressed ③ released ④ toggled
  • QToolButton: ① triggered
  • QAction: ① changed ② hovered ③ toggled ④ triggered

202207140001727.png

[TOC]

This article was originally published on ” Xie Zang’s Small Station “, and is reproduced here simultaneously.

outline

Signal difference of QAbstractButton / QToolButton / QAction

kind Signal
QAbstractButton void clicked(bool checked = false)
QAbstractButton void pressed()
QAbstractButton void released()
QAbstractButton void toggled(bool checked )
QToolButton void triggered(QAction * action )
QAction void changed()
QAction void hovered()
QAction void toggled(bool checked)
QAction void triggered(bool checked = false)

Four signals of QAbstractButton

  • clicked(bool checked ): Fired when the mouse is released . It will not fire if the mouse is dragged outside the button area and released. The corresponding function is *mouseReleaseEvent()*. In general, this signal is used in the connect slot function.

  • pressed(): emits a signal when the mouse is pressed . Corresponding to mousePressEvent()

  • released(): When the mouse is released , a signal is emitted. Fires even if the mouse is dragged outside the button area and released. Corresponding to mouseReleaseEvent()

  • toggled(bool checked ): Set the setCheckable(true) and then click the button to trigger the signal

Normally when a button is clicked, the response sequence is: pressed() — about 215ms — released() — almost 0ms — *clicked()*.

A signal of QToolButton

  • triggered(QAction * action ): emit a signal when the given QAction is triggered

Four Signals of QAction

  • changed(): emit a signal when the action changes
  • hovered(): This signal will be triggered as soon as the cursor moves to the range of the item and is overlaid on it.
  • toggled(bool checked): Set checkable(true) and then click the button to trigger this signal.
    1. eg: When the checkable is modified (check ☑, or uncheck ⬜), this signal will be triggered. This signal is also triggered when the function setChecked() is used.
    2. The actual measurement is to add QAction to the menu of QSystemTrayIcon; use this toggled signal, but the corresponding slot function will not be triggered? Strange. Triggered has been used instead of completion.
  • triggered(bool checked): Clicking the menu bar, toolbar button, or shortcut key of action can trigger this signal. But if functions like setChecked() , toggle() are called, it will not fire.

Serial address

QtExamples

Welcome to star ⭐ and fork ? this series of C++ / QT / DTK learning, with a list of learning from shallow to deep.

This article is reproduced from: https://ifmet.cn/posts/c554435b/
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment