• day0920


    1. #include
    2. #include
    3. QT_BEGIN_NAMESPACE
    4. namespace Ui { class Widget; }
    5. QT_END_NAMESPACE
    6. class Widget : public QWidget
    7. {
    8. Q_OBJECT
    9. public:
    10. Widget(QWidget *parent = nullptr);
    11. ~Widget();
    12. void paintEvent(QPaintEvent *event) override;
    13. void mousePressEvent(QMouseEvent *event) override;
    14. void mouseMoveEvent(QMouseEvent *event) override;
    15. private slots:
    16. void on_CloseBtn_clicked();
    17. private:
    18. Ui::Widget *ui;
    19. //定义个起始点
    20. QPoint StartPoint;
    21. int t_id;
    22. };
    23. #endif // WIDGET_H
    1. #include "widget.h"
    2. #include "ui_widget.h"
    3. Widget::Widget(QWidget *parent)
    4. : QWidget(parent)
    5. , ui(new Ui::Widget)
    6. {
    7. ui->setupUi(this);
    8. setWindowFlag(Qt::FramelessWindowHint);
    9. this->startTimer(1000);
    10. }
    11. Widget::~Widget()
    12. {
    13. delete ui;
    14. }
    15. void Widget::paintEvent(QPaintEvent *event)
    16. {
    17. //实例化一个画家类
    18. QPainter p(this);
    19. p.setFont(QFont("楷体"));
    20. //设置背景颜色
    21. p.setBrush(QBrush(QColor("pink")));
    22. p.translate(this->width()/2,this->height()/2);
    23. p.drawEllipse(QPoint(0,0),200,200);
    24. p.setPen(QColor("green"));
    25. for(int i=0; i<60; i++)
    26. {
    27. p.drawLine(200,0,195,0);
    28. p.rotate(6);
    29. }
    30. QPen pen;
    31. pen.setWidth(3);
    32. p.setPen(pen);
    33. for(int i=1; i<=12; i++)
    34. {
    35. p.rotate(30);
    36. p.drawLine(200,0,190,0);
    37. p.drawText(0,-175,QString("%1").arg(i));
    38. }
    39. QTime sysDate = QTime::currentTime();
    40. QString time = sysDate.toString();
    41. int h,m,s;
    42. QStringList list_time =time.split(":");
    43. h = list_time[0].toUInt();
    44. m = list_time[1].toUInt();
    45. s = list_time[2].toUInt();
    46. t_id = this->startTimer(1000);
    47. p.setPen(QColor("black"));
    48. p.setPen(pen);
    49. p.rotate(s*6);
    50. p.drawLine(0,0,0,-170);
    51. p.rotate(-s*6);
    52. pen.setWidth(2);
    53. p.setPen(pen);
    54. p.rotate(m*6 + s*6/60);
    55. p.drawLine(0,0,0,-120);
    56. p.rotate(-m*6 - s*6/60);
    57. pen.setWidth(3);
    58. p.setPen(pen);
    59. p.rotate((h%12)*30 + m*6/60 + s*6/60/12);
    60. p.drawLine(0,0,0,-80);
    61. p.rotate(-(h%12)*30 - m*6/60 - s*6/60/12);
    62. update();
    63. }
    64. void Widget::mousePressEvent(QMouseEvent *event)
    65. {
    66. StartPoint = event->globalPos() - this->frameGeometry().topLeft();
    67. }
    68. void Widget::mouseMoveEvent(QMouseEvent *event)
    69. {
    70. this->move(event->globalPos() - StartPoint);
    71. }
    72. void Widget::on_CloseBtn_clicked()
    73. {
    74. close();
    75. }

  • 相关阅读:
    LabVIEW中图像显示错误
    不同系統和流覽器如何檢查代理設置(Mac/Windows/Linux)
    Python学习记录 异常处理
    AM@有理函数的积分@有理分式积分
    H2N-Gly-Pro-Glu-COOH,32302-76-4
    Stm32_标准库_18_串口&蓝牙模块_手机与蓝牙模块通信_控制LED灯亮灭
    idea注释代码三种方式
    Mysql8.0 数据库表的基本操作
    记录一次线上gitlab11.x升级gitlab14.x版本操作
    28.在springboot中使用thymeleaf的内置对象(#request,#session,session)
  • 原文地址:https://blog.csdn.net/m0_73743794/article/details/133107076