QT中处理不同Windows(窗体中的)消息
為了能處理某些qt無法處理的事件,可以自己處理windows事件。
處理windows事件是重寫QApplication::winEventFilter(MSG*,long)函數來實現的。假如功能想捕獲所有在窗體上的鼠標中鍵按下的消息,需要繼承QApplication類:
class MyApplication:public QApplication
{
Q_OBJECT
public:
MyApplication(int argc,char *argv[]);
~MyApplication(){}
protected:
virtual bool winEventFilter(MSG *message, long *result);
signals:
void emit_signal();
};
將信號與槽連接起來:
然后重寫了winEventFilter函數,聲明一個信號。
bool MyApplication::winEventFilter(MSG *message, long *result)
{
switch(message->message)
{
case WM_MBUTTONDOWN:
emit emit_signal();
default:
break;
}
return QApplication::winEventFilter(message,result);
}
將windows消息中的WM_MBUTTONDOWN消息自定義的處理,但為了不影響默認處理,可以在最后一句中將消息和消息附加信息交給了基類的函數來處理。當你想過濾某種信息時候,可以在case語句中直接返回true,當返回false時候也會進行qt默認的處理。
總結
以上是生活随笔為你收集整理的QT中处理不同Windows(窗体中的)消息的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: F12 界面:请求响应内容 Previe
- 下一篇: 解决 idea 中 jsp 修改后页面