qt 学习笔记6 360 Labe

来源:互联网 发布:nginx alias用法 编辑:程序博客网 时间:2024/05/10 04:59


学习了qt 好多天,现在开始实战一些东西,首先拿360 开刀吧,练习练习,最终的效果是高仿360界面。

从最简单的开始,先实现360界面上分数部分的显示功能。

以下是运行效果:


代码相当简单,也就不多解释了:

#ifndef MYSCORELABEL_H#define MYSCORELABEL_H#include <QWidget>#include<QLabel>class myscoreLabel : public QLabel{    Q_OBJECTpublic:    explicit myscoreLabel(QString pixscore,QWidget*parent);protected:  void paintEvent(QPaintEvent*);private:  QPixmap m_pixscore;signals:public slots:};#endif // MYSCORELABEL_H#include "myscorelabel.h"#include<QPainter>myscoreLabel::myscoreLabel(QString pixscore,QWidget*parent):QLabel(parent){    m_pixscore=QPixmap(pixscore);}void myscoreLabel::paintEvent(QPaintEvent *){    QPixmap m_pixscoreborder(":/image/examine_score.png");    QPainter p(this);    p.drawPixmap(rect(),m_pixscoreborder);    p.drawPixmap((width()-m_pixscore.width())/2,(height()-m_pixscore.height())/2,m_pixscore);    QFont font;    font.setPixelSize(14);    p.setFont(font);    p.drawText(width()/2+m_pixscore.width()/2-5,height()/2+m_pixscore.height()/2-5,"分");}


0 0
原创粉丝点击