Qt模仿登录界面-页面反转效果
本文最后更新于:7 个月前
设置一个旋转效果,将登录界面旋转翻个面,设置一些网络参数。
效果
网络参数设置界面布局
网络参数设置界面
1 |
|
initMyTitle()
就不多说了,和正面登录界面差不多。
QPainterPath
类
它是由一些图形如曲线、矩形、椭圆组成的对象。主要的用途是,能保存已经绘制好的图形。实现图形元素的构造和复用;图形状只需创建一次,然后调用QPainter::drawPath()
函数多次绘制。painterpath
可以加入闭合或不闭合的图形( 如:矩形、椭圆和曲线) 。QPainterPath
可用于填充,描边,clipping 。
setFillRule()
设置填充模式
不是很理解
https://doc.qt.io/qt-5/qt.html#FillRule-enum
addRoundedRect(QRect(0, 0, this->width(), this->height()), 3, 3)
圆角矩形
QRect(0, 300, this->width(), this->height() - 300)
设置了矩形的位置及大小(3,3)
表示倒圆角的大小
setRenderHint()
开启反走样
QPainter::Antialiasing
告诉绘图引擎应该在可能的情况下进行边的反锯齿绘制QPainter::TextAntialiasing
尽可能的情况下文字的反锯齿绘制QPainter::SmoothPixmapTransform
使用平滑的pixmap变换算法(双线性插值算法),而不是近邻插值算
初始化旋转窗口
1 |
|
对正面和反面分别定义了信号槽,当对应的面接收到信号时,执行对应的动作。因为是旋转一百八十度,所以选择函数可以公用。
旋转窗口
1 |
|
QPropertyAnimation
动画类
QPropertyAnimation *rotateAnimation = new QPropertyAnimation(this, "rotateValue")
rotateValue
就是这个动画的属性,我们这个动画中变化的就是旋转值,也就是旋转角度。这个属性名完全自己起,也可以改成rotateAngle
等等,或者说想做一个平移的动画,也可以取一个moveDist
等名字。
下面这一串就是标准的一套动画流程
1 |
|
paintEvent
绘图事件
1 |
|
我们main
函数得知,最开始显示的窗口就是RotateWidget
。在实例化一个RotateWidget
类后,进行了标题栏的初始化工作,然后开始执行w.show()
显示,但是此时窗口是不显示的。这是因为我们在RotateWidget
的构造函数中进行了设置不显示窗口。
1 |
|
当运行到 return a.exec()
时,Qt会自动调用void RotateWidget::paintEvent()
。此时开始正式绘制窗口,但是因为我们还没哟点击登录页面的网络设置按钮,所以m_isRoratingWindow=0
。会调用父类的绘图事件,QStackedWidget::paintEvent()
,最后也就是BaseWindow::paintEvent()
。会将登录页面先绘制出来。
当我们点击网络设置按钮时,m_isRoratingWindow=1
开始绘制旋转画面。
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!