当前位置:网站首页>QT custom control 01 simple timer
QT custom control 01 simple timer
2022-04-21 23:27:00 【Grow some hair.】
Control for timing , Such as recording , When recording video , Or group chat, timing, etc 
class TimeRunningWidget : public QWidget
{
Q_OBJECT
public:
explicit TimeRunningWidget(QWidget* parent = nullptr);
~TimeRunningWidget();
void StartRun();
void StopRun();
void ClearTime();
private:
void InitWidget();
protected:
void paintEvent(QPaintEvent* e);
private:
QTimer *m_timer;
QTime m_time;
QString m_timeStr;
};
TimeRunningWidget::TimeRunningWidget(QWidget *parent):QWidget(parent)
{
InitWidget();
//Qt::WindowFlags flags = windowFlags();
//setWindowFlags( flags | Qt::FramelessWindowHint);
}
TimeRunningWidget::~TimeRunningWidget()
{
}
void TimeRunningWidget::StartRun()
{
m_timer->start();
}
void TimeRunningWidget::StopRun()
{
if(m_timer->isActive())
m_timer->stop();
}
void TimeRunningWidget::ClearTime()
{
if(m_timer->isActive())
m_timer->stop();
m_time.setHMS(0,0,0);
m_timeStr = m_time.toString("hh:mm:ss");
update();
}
void TimeRunningWidget::InitWidget()
{
m_timer = new QTimer(this);
m_timer->setInterval(1000);
m_time.setHMS(0,0,0);
m_timeStr = "00:00:00";
connect(m_timer,&QTimer::timeout,this,[this](){
m_time = m_time.addSecs(1);
m_timeStr = m_time.toString("hh:mm:ss");
update();
});
m_timer->start();
update();
}
void TimeRunningWidget::paintEvent(QPaintEvent *e)
{
Q_UNUSED(e);
QPainter painter;
painter.begin(this);
painter.setRenderHints(QPainter::Antialiasing, true);
QPen pen;
pen.setColor(Qt::red);
painter.setPen(pen);
painter.drawRoundedRect(1, 1, width()-2, height()-2, 16, 16);
painter.save();
QBrush br;
br.setStyle(Qt::SolidPattern);
br.setColor(Qt::red);
painter.setBrush(br);
painter.drawEllipse(QRect(10, height()/2 - 5 , 10, 10));
painter.restore();
painter.save();
pen.setColor(Qt::red);
painter.setPen(pen);
QFont font;
font.setBold(true);
font.setPixelSize(16);
painter.setFont(font);
painter.drawText(QRect(20,0,width()-20,height()), Qt::AlignCenter, m_timeStr);
painter.restore();
painter.end();
}
版权声明
本文为[Grow some hair.]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204212324101891.html
边栏推荐
- 通过点击导入的文件或点击组件进入对应的组件页面进行编辑
- The pattern should be large and the vision should be broad, and the humanitarian spirit should be upheld [continuous updating, do not delete]
- BUUCTF 你(竟)然赶我走
- 痞子衡嵌入式:聊聊系统看门狗WDOG1在i.MXRT1xxx系统启动中的应用及影响
- How does the applet integrate instant messaging with instant messaging
- 【H.264】H.264 解析 工具、web解析
- 继华为仓颉后,再现4款国产编程语言,形式多样,有一款0代码
- New independent version of the tiktok machine full repair version with video tutorial
- Buuctf, you drove me away
- golang力扣leetcode 388.文件的最长绝对路径
猜你喜欢

. 100 roller events

大厂面经合集,这些知识点你会吗

Find the first prime number greater than x (day 42)

87 r K-means, hierarchical clustering, implementation of EM clustering

339-Leetcode 单词规律

(3) Ruixin micro rk3568 SSH replaces dropbear

GIC spec之ITS和LPI中断5

Textview tilt properties

雲原生架構下的微服務選型和演進

How does the applet integrate instant messaging with instant messaging
随机推荐
手机APP游戏/软件/资源下载站/软件盒子源码
[reprint] postman omysql connection database
Basic concepts of audio and video and a simple introduction to ffmpeg
MySQL Chapter 5 addition, deletion, modification and query of MySQL table data
系列文章分类汇总(第二期)
MySQL Chapter 3 basic SQL syntax
Pytoch framework | torch nn. modules. Module(nn.Module)
Chapter 2 installation of MySQL database
Uni app image adaptation dynamic calculation of image height
[H.264] H.264 parsing tool, web parsing
selenium点击的元素被遮挡无法操作的解决办法
文件操作和IO
痞子衡嵌入式:聊聊系统看门狗WDOG1在i.MXRT1xxx系统启动中的应用及影响
[ffmpeg] command line
uni-app 图片适配 动态计算图片高度
SWOOLE高性能内存数据库的使用和配置教程
瑞芯微芯片AI部分开发记录 第一节 《PC端环境搭建1》
[H.264] SPS frame rate calculation method
[express agent operation] how to do cross-border e-commerce in 2022? Express will focus on three things this year
【ACM】46. Full Permutation (1. Here, the previous elements need to be used for permutation, so StartIndex is not used (only for combination and division); 2. Pay attention to whether the elements in t