1. 程式人生 > >Qt button() 與 buttons() 區別

Qt button() 與 buttons() 區別

QMouseEvent Class

QMouseEvent::button() const

Returns the button that caused the event

QMouseEvent::buttons() const

Returns the button state when the event was generated. The button state is a combination ofQt::LeftButton,Qt::RightButton,Qt::MidButtonusing 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返回"發生事件時哪些按鈕還處於按下狀態"