2015-10-18 62 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