2015-10-18 61 views
0

我想在QToolButton中使用HTML格式。例如在這張圖片中,我應該在「Sara」和「Online」中創建QToolButtonQToolButton不支持HTML

enter image description here

這裏是我的代碼:

viewControl=new QToolButton(this); 
QString labelText = "<P><b><i><FONT COLOR='#fff'>"; 
labelText .append("Sara"); 
labelText .append("</i></b></P></br>"); 
labelText .append("online"); 
viewControl->setText(labelText); 

但似乎QToolButton不能定義HTML格式。 enter image description here

如何解決?

我還在QToolButton中使用了佈局,但它顯示出空白框。

QVBoxLayout *titleLayout = new QVBoxLayout(); 
QLabel *nameLabel = new QLabel("Name"); 
QLabel *onlineLabel = new QLabel ("online"); 
titleLayout->addWidget(nameLabel); 
titleLayout->addWidget(onlineLabel); 
viewControl->setLayout(titleLayout); 
+0

爲什麼你認爲你可以在QToolButton中使用html? – perencia

+0

我在QLabel中使用了html,我想我可以在QToolButton中使用它。 @perencia – AFN

+0

你有沒有試過? http://libqxt.bitbucket.org/doc/tip/qxtpushbutton.html – ramtheconqueror

回答

1

根據該答覆中提到here

我不認爲這是可能沒有子QToolButton和重寫的paintEvent。但你可以嘗試這樣的事情:

toolButton->setStyleSheet("font-weight: Italic"); 
+0

非常感謝您的回答,儘管我想在QToolButton中創建多行。這並不能幫助我做到這一點。 – AFN