当前位置:网站首页>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;
}
边栏推荐
- 4G module initialization of charge point design
- Oracle database SQL statement execution plan, statement tracking and optimization instance
- Circular queue related design and implementation reference 1
- Open Euler Kernel Technology Sharing - Issue 1 - kdump Basic Principles, use and Case Introduction
- Vscode markdown export PDF error
- 要選擇那種語言為單片機編寫程序呢
- LeetCode - 508. 出现次数最多的子树元素和 (二叉树的遍历)
- Do you understand automatic packing and unpacking? What is the principle?
- The third paper of information system project manager in soft examination
- Seven sorting of ten thousand words by hand (code + dynamic diagram demonstration)
猜你喜欢
Schematic diagram and connection method of six pin self-locking switch
要选择那种语言为单片机编写程序呢
Openeuler kernel technology sharing - Issue 1 - kdump basic principle, use and case introduction
Education is a pass and ticket. With it, you can step into a higher-level environment
Adaptiveavgpool1d internal implementation
2021-10-27
2021-10-28
Yocto technology sharing phase IV: customize and add software package support
uniapp 实现微信小程序全局分享及自定义分享按钮样式
yocto 技術分享第四期:自定義增加軟件包支持
随机推荐
(2)接口中新增的方法
Vscode markdown export PDF error
Open Euler Kernel Technology Sharing - Issue 1 - kdump Basic Principles, use and Case Introduction
Seven sorting of ten thousand words by hand (code + dynamic diagram demonstration)
内存数据库究竟是如何发挥内存优势的?
You need to use MySQL in the opening experiment. How can you forget the basic select statement? Remedy is coming~
JS foundation - prototype prototype chain and macro task / micro task / event mechanism
Fundamentals of Electronic Technology (III)_ Chapter 2 principle of amplification circuit__ Crystal triode and field effect triode
Fundamentals of Electronic Technology (III)__ Fundamentals of circuit analysis__ Basic amplifier operating principle
4G module at command communication package interface designed by charging pile
2021-10-28
Stm32f04 clock configuration
Not many people can finally bring their interests to college graduation
There is no shortcut to learning and development, and there is almost no situation that you can learn faster by leading the way
Windows下MySQL的安装和删除
Design of charging pile mqtt transplantation based on 4G EC20 module
Timer and counter of 51 single chip microcomputer
Eight working modes of stm32gpio and chip naming rules
Working mode of 80C51 Serial Port
Fundamentals of Electronic Technology (III)__ Chapter 1 resistance of parallel circuit