• Qt事件


    1.每一个控件都有

    bool event(QEvent *event);    
    bool eventFilter(QObject *watched, QEvent *event);   //事件过滤器,就是什么控件想捕获怎样的事件  
    ui->label->installEventFilter(this);   //label控件安装过滤器
    ui->label->setMouseTracking(true);  //设置鼠标跟踪
    
    bool Widget::eventFilter(QObject *watched, QEvent *event)
    {
        if(watched == ui->label)
        {
            static int t = 0;
            QMouseEvent *env = (QMouseEvent *)(event);  //鼠标事件
            if(event->type() == QEvent::MouseMove)   //移动事件
            {
                ui->label->setText(QString("%1").arg(t++));
                return true;
            }
        }
       return QWidget::eventFilter(watched,event);
    }

     2.重绘控件在布局中的位置和大小

    void Widget::paintEvent(QPaintEvent* e)
    {
        //_curve->update();
        ui->label_show->setGeometry((ui->groupBox->width() - ui->label_show->height())/2,
                                    (ui->groupBox->height() - ui->label_show->height()+9)/2,
                                     ui->label_show->height(),
                                     ui->label_show->height());
    }
    
    
  • 相关阅读:
    博途Portal TIA(PLC) + Scout (独立)驱动配置 CU320 + PM240-2
    TM41 修改分辨率
    用户注册
    用户名的登录认证
    CSS
    HTML
    python常用模块
    面对对象进阶
    面对对象之绑定方法和非绑定方法
    面对对象之封装
  • 原文地址:https://www.cnblogs.com/mathyk/p/9902189.html
Copyright © 2020-2023  润新知