Two colours text in QPushButton

后端 未结 3 438
失恋的感觉
失恋的感觉 2020-12-20 21:06

I need a QPushButton with two colors in the text. I found a solution with a html code in QTextDocument and it\'s working. But I need center align and the html code isn\'t wo

3条回答
  •  心在旅途
    2020-12-20 21:21

    You can derive from QPushButton and draw text yourself via QPainter in paintEvent.

    class Button : public QPushButton
    {
    Q_OBJECT
    
    public:
    Button(QWidget *parent = 0)
    : QPushButton(parent)
        { }
    
    void paintEvent(QPaintEvent *p)
        {
            QPushButton::paintEvent(p);
            QPainter paint(this);
            paint.drawText(QPoint(10,10),"Hello");
        }
    };
    

提交回复
热议问题