zoukankan      html  css  js  c++  java
  • [Qt] 事件机制(四)

    滚轮事件:滚动滚轮实现窗口大小缩放

    widget.h中增加:

    protected:
        void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE;
        void extendWindowsSize();
        void shrinkWindowsSize();
    private:
        int m_originalWidth;
        int m_originalHeight;

    widget.cpp中增加:

     1 Widget::Widget(QWidget *parent) :
     2     QWidget(parent),
     3     ui(new Ui::Widget)
     4 {
     5     ...
     6     m_originalWidth=this->width();
     7     m_originalHeight=this->height();
     8 }
     9 void Widget::wheelEvent(QWheelEvent *event){
    10     QWidget::wheelEvent(event);
    11     QPoint scroll = event->angleDelta();
    12     if(scroll.y()>0){
    13         extendWindowsSize();
    14     }else{
    15         shrinkWindowsSize();
    16     }
    17 }
    18 void Widget::extendWindowsSize(){
    19     if(this->width()>m_originalWidth+300){
    20         return;
    21     }
    22     this->setMaximumSize(this->width()+10,this->height()+10);
    23     this->setMinimumSize(this->width()+10,this->height()+10);
    24 }
    25 void Widget::shrinkWindowsSize(){
    26     if(this->width()<m_originalWidth-300){
    27         return;
    28     }
    29     this->setMinimumSize(this->width()-10,this->height()-10);
    30     this->setMaximumSize(this->width()-10,this->height()-10);
    31 }

    参考:

    https://blog.csdn.net/qq78442761/article/details/85104679

    https://blog.csdn.net/qq78442761/article/details/81503006

    void setResizeAnchor(ViewportAnchor anchor);

    QGraphicsView::AnchorViewCenter

  • 相关阅读:
    【u026】花园(garden)
    【BZOJ 1040】[ZJOI2008]骑士
    【t100】汤姆斯的天堂梦
    【BZOJ 1038】[ZJOI2008]瞭望塔
    【t096】树的序号
    Java Web整合开发(82)
    2 HTML解析
    T3186 队列练习2 codevs
    T3185 队列练习1 codevs
    T1191 数轴染色 codevs
  • 原文地址:https://www.cnblogs.com/cxc1357/p/12010958.html
Copyright © 2011-2022 走看看