当前位置:网站首页>QT self drawing button with bubbles
QT self drawing button with bubbles
2022-07-03 10:02:00 【Master Hao】
#include
#include
class QTipButton : public QPushButton
{
public:
QTipButton(QWidget *parent);
virtual ~QTipButton(void);
virtual void paintEvent(QPaintEvent * event);
void setButtonNum(int buttonNum);
private:
int _buttonNum=0;
};
#include “qtipbutton.h”
#include “qpainter.h”
#include “QRgb”
QTipButton::QTipButton(QWidget *parent)
: QPushButton(parent)
{
}
QTipButton::~QTipButton(void)
{
}
void QTipButton::paintEvent(QPaintEvent * event)
{
QPainter painter(this);
painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);// Anti-Aliasing , Anti aliasing
QRect rt = rect();
QRect rt1 = QRect(rt.left()+rt.width()*0.70, (rt.top()+rt.height()*0.15), rt.height()*0.7, rt.height()*0.7);
QRect rt2 = QRect(rt.left(), rt.top(),
rt.width(), rt.height());
if(this->isChecked())
{
painter.fillRect(rt2, QColor(34,160,108));
painter.setPen(Qt::white);
painter.drawText(rt, Qt::AlignCenter, text());
}
else
{
painter.fillRect(rt2, QColor(71, 102, 92));
painter.setPen(Qt::white);
painter.drawText(rt, Qt::AlignCenter, text());
}
painter.setPen(QColor(163, 0, 20));
painter.setBrush(QBrush(Qt::red));
if( _buttonNum!=0)
{
painter.drawEllipse(rt1);
}
painter.setPen(Qt::white);
if( _buttonNum!=0)
{
painter.drawText(rt1, Qt::AlignCenter, QString::number(_buttonNum));
}
}
void QTipButton::setButtonNum(int buttonNum)
{
_buttonNum = buttonNum;
}

边栏推荐
- Quelle langue choisir pour programmer un micro - ordinateur à puce unique
- It is difficult to quantify the extent to which a single-chip computer can find a job
- Exception handling of arm
- 内存数据库究竟是如何发挥内存优势的?
- 要选择那种语言为单片机编写程序呢
- A lottery like scissors, stone and cloth (C language)
- Seven sorting of ten thousand words by hand (code + dynamic diagram demonstration)
- 4G module board level control interface designed by charging pile
- The third paper of information system project manager in soft examination
- 2021-10-27
猜你喜欢

2312、卖木头块 | 面试官与狂徒张三的那些事(leetcode,附思维导图 + 全部解法)

Timer and counter of 51 single chip microcomputer

My notes on the development of intelligent charging pile (III): overview of the overall design of the system software

Getting started with JMX, MBean, mxbean, mbeanserver

单片机职业发展:能做下去的都成牛人了,熬不动就辞职或者改行了

STM32 port multiplexing and remapping

我想各位朋友都应该知道学习的基本规律就是:从易到难

It is difficult to quantify the extent to which a single-chip computer can find a job

Project cost management__ Topic of comprehensive calculation

03 FastJson 解决循环引用
随机推荐
CEF download, compile project
Programming ideas are more important than anything, not more than who can use several functions, but more than the understanding of the program
(2)接口中新增的方法
2. Elment UI date selector formatting problem
2021-10-28
2020-08-23
QT qcombobox QSS style settings
Serial port programming
4G module board level control interface designed by charging pile
51 MCU tmod and timer configuration
My notes on the development of intelligent charging pile (III): overview of the overall design of the system software
单片机现在可谓是铺天盖地,种类繁多,让开发者们应接不暇
Gpiof6, 7, 8 configuration
[Li Kou brush question notes (II)] special skills, module breakthroughs, classification and summary of 45 classic questions, and refinement in continuous consolidation
Pymssql controls SQL for Chinese queries
03 fastjason solves circular references
STM32 external interrupt experiment
STM32 general timer 1s delay to realize LED flashing
单片机学到什么程度能找到工作,这个标准不好量化
2020-08-23