zoukankan      html  css  js  c++  java
  • 处理鼠标响应事件(最简单控件 good)

    贴下代码:

    #ifndef MYWIDGET_H
    #define MYWIDGET_H

    #include <QWidget>
    #include <QtGui>
    #include <QMouseEvent>

    class MyWidget : public QWidget
    {
    public:
        MyWidget();
        void mousePressEvent(QMouseEvent *event);
        void mouseMoveEvent(QMouseEvent *event);
        void mouseReleaseEvent(QMouseEvent *event);
        void paintEvent(QPaintEvent *event);

    private:
        QPoint m_PointStart;
        QPoint m_PointEnd;
    };

    #endif // MYWIDGET_H
    #include <QtGui/QApplication>
    #include "mainwindow.h"

    #include "mywidget.h"

    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MyWidget widget;
        widget.show();

        return a.exec();
    }
    #include "mywidget.h"

    MyWidget::MyWidget()
    {
        resize(240,320);
    }

    void MyWidget::mousePressEvent(QMouseEvent *event)
    {
        m_PointStart = event->pos();

    }

    void MyWidget::mouseMoveEvent(QMouseEvent *event)
    {
        //m_PointEnd = event->pos();
       //update();
    }

    void MyWidget::mouseReleaseEvent(QMouseEvent *event)
    {
        m_PointEnd = event->pos();
        update();
    }

    void MyWidget::paintEvent(QPaintEvent *event)
    {
        QPainter painter(this);
        painter.setBrush(QBrush(QColor(255,0,0)));
        painter.drawPixmap(0,0,240,320,QPixmap("images/frame1.jpg"));

        if(m_PointStart.x() < m_PointEnd.x())
            painter.drawPixmap(0,0,240,320,QPixmap("images/frame2.jpg"));
        else if(m_PointStart.x() > m_PointEnd.x())
            painter.drawPixmap(0,0,240,320,QPixmap("images/frame3.jpg"));

    }

    http://www.cppblog.com/qianqian/archive/2010/07/27/121418.html

  • 相关阅读:
    java native 跨语言开发
    tomcat 加载 war包
    AWS
    云主机的体系架构
    数据流程图
    html5 创收
    javascript 发展
    营利模式
    错误:Reference file contains errors http://www.ibm.com/webservices/xsd/j2ee_web_services_client_1_1.xsdv......
    android eclipse 项目相互引用设置
  • 原文地址:https://www.cnblogs.com/findumars/p/5805090.html
Copyright © 2011-2022 走看看