Qt button() 與 buttons() 區別

QMouseEvent Class

Qt::MouseButton QMouseEvent::button() const

Returns the button that caused the event

Qt::MouseButtons QMouseEvent::buttons() const

Returns the button state when the event was generated. The button state is a combination of Qt::LeftButton, Qt::RightButton,Qt::MidButton using the OR operator. For mouse move events, this is all buttons that are pressed down. For mouse press and double click events this includes the button that caused the event. For mouse release events this excludes the button that caused the event.

假設你的鼠標左鍵已經按下。 如果移動鼠標,會發生的move事件,button返回Qt::NoButton,buttons返回LeftButton。 再按下了右鍵,會發生press事件,button返回RightButton,buttons返回LeftButton|RightButton 再移動鼠標,會發生move事件,button返回Qt::NoButton,buttons返回LeftButton|RightButton 再鬆開左鍵,會發生Release事件,button返回LeftButton,buttons返回RightButton 也就是說,button返回“那個按鈕發生了此事件”,buttons返回"發生事件時哪些按鈕還處於按下狀態"
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章