久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

QPushButton 中的兩種顏色文本

Two colours text in QPushButton(QPushButton 中的兩種顏色文本)
本文介紹了QPushButton 中的兩種顏色文本的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我需要一個文本中有兩種顏色的 QPushButton.我在 QTextDocument 中找到了一個帶有 html 代碼的解決方案,并且它正在運行.但是我需要居中對齊并且 html 代碼不起作用.

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 working.

 QTextDocument Text;
  Text.setHtml("<p align=center><font>Button</font><br/><font color=yellow>1</font></p>");

   QPixmap pixmap(Text.size().width(), Text.size().height());
   pixmap.fill( Qt::transparent );
   QPainter painter(&pixmap);
   Text.drawContents(&painter, pixmap.rect());

   QIcon ButtonIcon(pixmap);
   ui->toolButton->setText("");
   ui->toolButton->setIcon(ButtonIcon);
   ui->toolButton->setIconSize(pixmap.rect().size());

我明白了,

相同的代碼 HTML 在 QLabel 中工作

The same code HTML is working in a QLabel

ui->label->setText("<p align=center><font>Label</font><br/><font color=yellow>1</font></p>");

有什么解決辦法嗎?

非常感謝.

推薦答案

你可以從QPushButton派生出來,通過paintEvent中的QPainter自己繪制文本.

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");
    }
};

這篇關于QPushButton 中的兩種顏色文本的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數據?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環: for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環?)
Reusing thread in loop c++(在循環 C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環形?)
主站蜘蛛池模板: 国产成人精品午夜视频免费 | 日本在线视频中文字幕 | av一二三四 | 欧美综合一区二区三区 | av黄色免费 | 亚洲成av人影片在线观看 | 国产精品一区二区三区久久 | 国产高清在线 | 黄色a级一级片 | 特级特黄特色的免费大片 | 久久久91 | 久久成人av电影 | 日日干夜夜操 | 91精品国产欧美一区二区成人 | 亚洲视频在线看 | 伊人啪啪网| 亚洲综合天堂 | 日韩一区二区三区视频 | 亚洲精品国产一区 | 欧美一区二区三区视频 | 99久久精品国产麻豆演员表 | 亚洲精品一区国语对白 | 欧美二区乱c黑人 | 亚洲视频免费在线 | 免费看a| 天天干视频在线 | 午夜精品久久久久久不卡欧美一级 | 福利社午夜影院 | 国产a一区二区 | 欧美中文字幕 | 野狼在线社区2017入口 | 午夜寂寞影院在线观看 | 国产一级在线视频 | 亚洲毛片在线 | 欧美一区二区三区在线视频 | 天天草天天爱 | 欧美日韩国产高清视频 | 可以免费观看的av片 | 中文字幕视频在线观看 | 欧美成人h版在线观看 | 国产精品无 |