Analog Clock Window Example
Qt 5.10.0 Reference Documentation Contents class AnalogClockWindow : public RasterWindow protected: private: AnalogClockWindow::AnalogClockWindow() m_timerId = startTimer(1000); We set a title on the window and resize to a reasonable size. Then we start a timer which we will use to redraw the clock every second. void AnalogClockWindow::timerEvent(QTimerEvent *event) The timerEvent function is called every second as a result of our startTimer call. Making use of the convenience in the base class,we schedule the window to be repainted. void AnalogClockWindow::render(QPainter *p) QColor hourColor(127,127); Before we set up the painter and draw the clock,we first define two lists of QPoints and two QColors that will be used for the hour and minute hands. The minute hand‘s color has an alpha component of 191,meaning that it‘s 75% opaque. p->setRenderHint(QPainter::Antialiasing); We call QPainter::setRenderHint() with QPainter::Antialiasing to turn on antialiasing. This makes drawing of diagonal lines much smoother. p->translate(width() / 2,height() / 2); int side = qMin(width(),height()); The translation moves the origin to the center of the window,and the scale operation ensures that the following drawing operations are scaled to fit within the window. We use a scale factor that let‘s us use x and y coordinates between -100 and 100,and that ensures that these lie within the length of the window‘s shortest side. p->setPen(Qt::NoPen); We set the pen to be Qt::NoPen because we don‘t want any outline,and we use a solid brush with the color appropriate for displaying hours. Brushes are used when filling in polygons and other geometric shapes. QTime time = QTime::currentTime(); p->save(); We save and restore the transformation matrix before and after the rotation because we want to place the minute hand without having to take into account any previous rotations. p->setPen(hourColor); for (int i = 0; i < 12; ++i) { We draw markers around the edge of the clock for each hour. We draw each marker then rotate the coordinate system so that the painter is ready for the next one. p->setPen(Qt::NoPen); The minute hand is rotated in a similar way to the hour hand. p->setPen(minuteColor); for (int j = 0; j < 60; ++j) { Again,we draw markers around the edge of the clock,but this time to indicate minutes. We skip multiples of 5 to avoid drawing minute markers on top of hour markers.Files:analogclock/analogclock.proanalogclock/main.cpp ? 2017 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners.The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation.Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- hp-proliant – HP DL320e Gen8,3TB驱动器,Windows Server
- 如何使用Windows身份验证对中间层上的用户进行身份验证
- windows-server-2008-r2 – 没有源IP的事件ID 4625
- active-directory – 在Windows 7上,您需要将哪种类型的权限
- winapi – 在MS Windows(XP)上使用来自不同进程的窗口句柄进
- DHCP 协议原理以及如何配置 DHCP
- windows-server-2008 – DFS-R替代品?
- assembly – 64位Windows汇编程序
- winapi – 使用Windows SetTimer()函数
- active-directory – Windows 10,RSAT工具缺少功能
- window.location.replace和window.location.href
- Windows数据类型…为什么这么多/不可写?
- Windows中为Latex添加.sty文件
- 测试dos攻击对openflow中flow_table溢出的影响
- windows – 在CMD中重命名文件日期的文件
- cmd – Windows 10托管网络=“否”,如何强制是
- win7上的WCF Duplex net.tcp问题
- 将uint8_t作为int8_t进行便携式重新解释并强制对
- iis – 在端口80上的Windows Server 2012上运行G
- windows – 如何正确调用LsaLogonUser进行交互式