• 聊天软件中的窗口上滑和下滑提示上下线


    聊天软件中右下角窗口上滑提示有好友上线,窗口下滑提示有好友下线。

    在 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 QMainWindow
    13 {
    14     Q_OBJECT
    15     
    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

    当你坚持做一件完全正确的事情,有可能在很长一段时间内,你的价值都是零。
  • 相关阅读:
    [eZ publish] Get Start a new eZ Publish projectTwo
    [eZ publish] Get Start a new eZ Publish projectOne
    [Ubuntu] Ubuntu8.10下NetBeans6.5中文变成方块解决
    [Ubuntu] 安装/卸载 声卡驱动
    [eZ publish] Url filter
    [eZ publish] How to use multiple pagelayouts
    [Ubuntu] 给系统监视器加个快捷键
    [Ubuntu] 如何添加自定义命令
    软件的价值(转)
    C语言程序收集
  • 原文地址:https://www.cnblogs.com/lweleven/p/onlinewaring.html
Copyright © 2020-2023  润新知