常用控件
- 一.ProgressBar
- [二. Calendar Widget](#二. Calendar Widget)
一.ProgressBar
使⽤ QProgressBar 表⽰⼀个进度条


代码⽰例:设置进度条按时间增⻓
设置定时器,每个0.1秒,让进度条+1



在实际开发中,进度条的取值,往往是根据当前任务的实际进度来进行设置的。比如需要读取一个很大的文件,就可以获取文件的总的大小,和当前读取完毕的大小,来设置进度条的比例。由于上面我们介绍了Qt禁止在其他线程修改界面,因此进度条的更新往往也是需要搭配定时器来完成的。通过定时器周期触发信号,主线程调用对应的slot函数。再在slot 函数中对当前的任务进度进行计算,并更新进度条的界面效果。
代码⽰例:创建⼀个红⾊的进度条
不要忘了,QProgressBar同样也是 Qwidget的子类,因此我们可以使用styleSheet通过样式来修改进度条的颜色.

QProgressBar::chunk {background-color: #FF0000;}
其中的 chunk是选中进度条中的每个"块".使用QProgressBar::text则可以选中文本.

同时把QProcessBar 的alignment属性设置为垂直水平居中.


二. Calendar Widget
QCalendarWidget 表⽰⼀个"⽇历",形如:

核心属性:

重要信号:


代码⽰例:获取选中的⽇期
