@@ -17,6 +17,7 @@ NetIconButton::NetIconButton(QWidget *parent)
1717 , m_clickable(false )
1818 , m_rotatable(false )
1919 , m_hover(false )
20+ , m_textType(true )
2021{
2122 setAccessibleName (" NetIconButton" );
2223 setFixedSize (24 , 24 );
@@ -50,6 +51,12 @@ void NetIconButton::setRotatable(bool rotatable)
5051 }
5152}
5253
54+ void NetIconButton::setTextType (bool textType)
55+ {
56+ m_textType = textType;
57+ update ();
58+ }
59+
5360void NetIconButton::startRotate ()
5461{
5562 if (!m_refreshTimer) {
@@ -93,18 +100,27 @@ void NetIconButton::paintEvent(QPaintEvent *e)
93100 return ;
94101 QPainter painter (this );
95102 painter.setRenderHints (QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
96-
103+ QRect r = rect ();
97104 if (m_rotateAngle != 0 ) {
98- painter.translate (this -> width () / 2 , this -> height () / 2 );
105+ painter.translate (r. width () / 2 , r. height () / 2 );
99106 painter.rotate (m_rotateAngle);
100- painter.translate (-(this -> width () / 2 ), -(this -> height () / 2 ));
107+ painter.translate (-(r. width () / 2 ), -(r. height () / 2 ));
101108 }
102-
109+ const qreal scale = devicePixelRatio ();
110+ QSize pixmapSize = r.size () * scale;
111+ QPixmap pm;
103112 if (m_hover && !m_hoverIcon.isNull ()) {
104- m_hoverIcon.paint (&painter, rect () );
113+ pm = m_hoverIcon.pixmap (pixmapSize );
105114 } else {
106- m_icon.paint (&painter, rect ());
115+ pm = m_icon.pixmap (pixmapSize);
116+ }
117+ if (m_textType) {
118+ QPainter pa (&pm);
119+ pa.setCompositionMode (QPainter::CompositionMode_SourceIn);
120+ pa.fillRect (r, painter.pen ().brush ());
107121 }
122+ pm.setDevicePixelRatio (scale);
123+ painter.drawPixmap (r, pm);
108124}
109125
110126void NetIconButton::mousePressEvent (QMouseEvent *event)
0 commit comments