成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

QT平臺上模擬鼠標事件案例

移動開發
QT平臺上模擬鼠標事件案例是本文要介紹的內容,主要是來了解QT平臺上的模擬鼠標事件的應用,具體內容的實現來看本文詳解。

QT平臺模擬鼠標事件案例是本文要介紹的內容,主要是來了解QT平臺上的模擬鼠標事件的應用,具體內容的實現來看本文詳解。需要導入QTest4.lib 否則會有連接時錯誤

  1. #include<QtTest/QTest> 
  2. QTest::mouseClick(ui.mainPlayer,Qt::LeftButton,0,pos(),-1); 

QT平臺模擬鼠標按鍵

和模擬鍵盤按鍵類似,也是通過發送相應的事件來實現的,安裝相應的事件監聽器,具體發送事件:

  1. QPoint pos;  
  2. pos.setX(88);  
  3. pos.setY(58);  
  4. QMouseEvent *mEvnPress;  
  5. QMouseEvent *mEvnRelease;  
  6. mEvnPress = new QMouseEvent(QEvent::MouseButtonPress, pos, Qt::LeftButton,Qt::LeftButton, Qt::NoModifier);  
  7. QApplication::sendEvent(QWidget::focusWidget(),mEvnPress);  
  8. mEvnRelease = new QMouseEvent(QEvent::MouseButtonRelease, pos, Qt::LeftButton,Qt::LeftButton, Qt::NoModifier);  
  9. QApplication::sendEvent(QWidget::focusWidget(),mEvnRelease);       

主要的分析函數是:    

  1. QMouseEvent::QMouseEvent ( Type type, const QPoint & position,Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiersmodifiers ) 

參數分析:

  1. The type parameter must be one of QEvent::MouseButtonPress,QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick, or QEvent::MouseMove.  
  2. The position is the mouse cursor's position relative to the receiving widget.   
  3. The button that caused the event is given as a value from the Qt::MouseButtonenum.   
  4.       If the event type is MouseMove, the appropriate button for this event isQt::NoButton.   
  5. The mouse and keyboard states at the time of the event are specified by buttonsand modifiers.  
  6. The globalPos() is initialized to QCursor::pos(), which may not be appropriate.Use the other constructor to specify the global position explicitly. 

主要說明:

這里的pos的位置是接受鼠標事件的widget的內部的一個局部位置。也就是說他的鼠標按鍵的產生點是:先通過QApplication::sendEvent(QWidget::focusWidget(),mEvnPress);//也就是說先是指明了傳遞給哪個widget,然后再根據mEventPress來進行具體的再改widget中的定位,以及具體的按鍵是什么。

  1. bool MainWidget::eventFilter(QObject*target, QEvent *event)  
  2. {  
  3.    if(event->type()==QEvent::FocusIn){//event->type()==QEvent::Enter||  
  4.        static_cast<QPushButton*>(target)->setStyleSheet("background-color:rgb(129, 129,129)");  
  5.  
  6.        QPalette pal;  
  7.      pal.setColor(QPalette::Active,QPalette::ButtonText,Qt::red);          
  8.        static_cast<QPushButton*>(target)->setPalette(pal);  
  9.    }  
  10.    elseif(event->type()==QEvent::FocusOut){//event->type()==QEvent::Leave ||  
  11.        static_cast<QPushButton*>(target)->setStyleSheet("");  
  12.        QPalette pal;  
  13.        pal.setColor(QPalette::Active,QPalette::ButtonText,Qt::black);  
  14.        static_cast<QPushButton*>(target)->setPalette(pal);  
  15.    }  
  16.    else if(event->type()== QEvent::KeyPress){  
  17.        QPoint pos;  
  18.        QWidget *now_buttonQWidget::focusWidget();  
  19.        QKeyEvent *k = (QKeyEvent *)event;  
  20.        QLayoutItem *next_button;  
  21.        switch (k->key()){  
  22.        case Qt::Key_Up:  
  23.             next_button=ui->gridLayout->itemAt((ui->gridLayout->indexOf(now_button)+8)%12);  
  24.             next_button->widget()->setFocus();  
  25.             break;  
  26.        case Qt::Key_Down:  
  27.             next_button=ui->gridLayout->itemAt((ui->gridLayout->indexOf(now_button)+4)%12);  
  28.            next_button->widget()->setFocus();  
  29. #ifdef COURSE  
  30.             QCursor::setPos(pos);  
  31. #endif  
  32.             break;  
  33.        case Qt::Key_Left:  
  34.             next_button=ui->gridLayout->itemAt((ui->gridLayout->indexOf(now_button)-1+12)%12);  
  35.            next_button->widget()->setFocus();  
  36. #ifdef COURSE  
  37.             QCursor::setPos(pos);  
  38. #endif  
  39.             break;  
  40.        case Qt::Key_Right:  
  41.             next_button=ui->gridLayout->itemAt((ui->gridLayout->indexOf(now_button)+1)%12);  
  42.            next_button->widget()->setFocus();  
  43.             break;  
  44.        case Qt::Key_Period:  
  45.             pos = now_button->pos();  
  46.             pos.setX( 20 +pos.x()+(now_button->width())/2 );  
  47.             pos.setY( 20 +pos.y()+(now_button->height())/2 );  
  48.             //printf("/n***%d1%d***/n",pos.x(),pos.y());  
  49. #ifdef COURSE  
  50.             QCursor::setPos(pos);  
  51. #endif  
  52.             pos.setX(88);  
  53.             pos.setY(58);  
  54.             QMouseEvent *mEvnPress;  
  55.             QMouseEvent *mEvnRelease;  
  56.             mEvnPress = newQMouseEvent(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,Qt::NoModifier);  
  57.            QApplication::sendEvent(QWidget::focusWidget(),mEvnPress);  
  58.             mEvnRelease = newQMouseEvent(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,Qt::NoModifier);  
  59.            QApplication::sendEvent(QWidget::focusWidget(),mEvnRelease);  
  60.             next_button =ui->gridLayout->itemAt(ui->gridLayout->indexOf(QWidget::focusWidget()));  
  61.             break;  
  62.        default:  
  63.             returnQWidget::eventFilter(target,event);  
  64.        }  
  65.  
  66.        if(next_button){  
  67.             pos.setX( 20 +next_button->geometry().x() + (next_button->geometry().width()) / 2 );  
  68.             pos.setY( 20 +next_button->geometry().y() + (next_button->geometry().height()) / 2);  
  69. #ifdef COURSE  
  70.             QCursor::setPos(pos);  
  71. #endif  
  72.        }  
  73.        return true;  
  74.    }  
  75.    return QWidget::eventFilter(target,event);  

小結:QT平臺模擬鼠標事件案例的內容介紹完了,希望通過QT平臺模擬鼠標內容的學習能對你有所幫助!

責任編輯:zhaolei 來源: 互聯網
相關推薦

2011-08-29 11:25:29

QTWebKit鼠標

2012-06-12 09:43:34

微軟Linux服務

2009-01-16 09:10:39

JavaCRM系統企業應用

2010-06-09 17:46:53

2013-05-14 11:08:23

AIR Android觸摸事件鼠標事件

2009-12-30 10:44:38

Silverlight

2016-12-28 09:30:37

Andriod安卓平臺依賴注入

2017-02-23 13:51:05

2019-11-26 14:52:40

Linux工具寫作者

2011-07-28 15:07:23

iOS猜數游戲

2017-03-20 17:20:35

iOSTensorFlow

2013-08-27 10:31:05

Headless模式Java SE設計模式

2011-06-23 14:05:32

Qt 事件機制

2011-06-22 10:20:11

QT 鼠標 拖放

2017-11-06 08:52:59

Linux終端模擬器Java 9

2010-01-04 14:06:35

Silverlight

2010-03-22 09:30:55

Linux非開源軟件

2011-12-01 11:36:42

云計算蘋果谷歌

2015-07-08 11:28:53

云服務平臺Docker MachDocker

2017-09-28 09:25:50

SQL ServerLinuxWindows
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 成人黄色三级毛片 | 激情毛片| 精品成人一区二区 | 二区不卡 | 色播99| 人人澡视频 | 欧美日韩国产在线观看 | 欧美成人精品 | 精品久久一 | 黄网站免费观看 | 日韩福利在线观看 | 在线视频第一页 | 国产精品九九九 | 久草视频在 | 久久狠狠| 国产欧美精品一区 | 涩在线| 亚洲国产aⅴ成人精品无吗 综合国产在线 | 久久精品亚洲欧美日韩久久 | 一区二区三区在线 | 国产一区二区精品在线观看 | 97人人澡人人爽91综合色 | 亚洲欧美日韩精品 | 五月婷婷导航 | 成人av一区 | 97国产成人 | 亚洲国产高清高潮精品美女 | 久久9视频| 成人免费在线 | 成人精品视频在线 | av中文字幕网站 | 99在线精品视频 | 婷婷激情五月网 | 青青久在线视频 | 久久久久久国产精品免费免费男同 | 男女羞羞视频在线 | 久久精品视频在线免费观看 | 国产一二三区在线 | 国产成在线观看免费视频 | 91xxx在线观看 | 国产精品福利在线观看 |