聊天軟體中的視窗上滑和下滑提示上下線

來源:互聯網
上載者:User

標籤:style   blog   color   os   2014   art   div   ar   

聊天軟體中右下角視窗上滑提示有好友上線,視窗下滑提示有好友下線。

在 Qt 下實現此功能,用到的類有 QPoint  QTimer

mainwindow.h

 

 1 #ifndef MAINWINDOW_H 2 #define MAINWINDOW_H 3  4 #include <QMainWindow> 5 #include <QPoint> 6 #include <QTimer> 7  8 namespace Ui { 9 class MainWindow;10 }11 12 class MainWindow : public QMainWindow13 {14     Q_OBJECT15     16 public:17     explicit MainWindow(QWidget *parent = 0);18     void point_to_point();19     ~MainWindow();20     21 private:22     Ui::MainWindow *ui;23     QTimer* M_Timer;24     QTimer* M_Timer1;25     QTimer* M_Timer2;26     int Counter;27     QPoint curPos;28 29 private slots:30     void timerDone();31     void timerDone1();32     void timerDone2();33 };34 35 #endif // MAINWINDOW_H

 

 

 

 

 mainwindow.cpp

 1 #include "mainwindow.h" 2 #include "ui_mainwindow.h" 3  4 MainWindow::MainWindow(QWidget *parent) : 5     QMainWindow(parent), 6     ui(new Ui::MainWindow) 7 { 8     ui->setupUi(this); 9     M_Timer = new QTimer();10     M_Timer1 = new QTimer();11     M_Timer2 = new QTimer();12     this->move(950,768);13     curPos=this->pos();14     connect(M_Timer, SIGNAL(timeout()),this, SLOT(timerDone()));15     connect(M_Timer1, SIGNAL(timeout()),this, SLOT(timerDone1()));16     connect(M_Timer2, SIGNAL(timeout()),this, SLOT(timerDone2()));17     point_to_point();18 }19 20 MainWindow::~MainWindow()21 {22     delete ui;23 }24 25 void MainWindow :: point_to_point()26 {27     M_Timer->start(100);28     curPos=this->pos();29     QPoint TmpPos(curPos.x(),curPos.y()-10);30     this->move(TmpPos);31 }32 33 void MainWindow :: timerDone()34 {35     curPos=this->pos();36     QPoint TmpPos(curPos.x(),curPos.y()-10);37     this->move(TmpPos);38     Counter = curPos.y();39     qDebug() << curPos.y();40     if(Counter < 500)41     {42        M_Timer->stop();43        M_Timer2->start(1000);44     }45 }46 47 void MainWindow :: timerDone1()48 {49     curPos=this->pos();50     QPoint TmpPos(curPos.x(),curPos.y()+10);51     this->move(TmpPos);52     Counter = curPos.y();53     if(Counter > 660)54     {55         M_Timer1->stop();56     }57 }58 59 void MainWindow :: timerDone2()60 {61     curPos=this->pos();62     QPoint TmpPos(curPos.x(),curPos.y());63     this->move(TmpPos);64     M_Timer2->stop();65     M_Timer1->start(100);66 }

 

2014-07-28   21:03:08

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.