【问题标题】:QToolButton doesn't support HTMLQToolButton 不支持 HTML
【发布时间】:2015-10-18 11:38:17
【问题描述】:

我想在QToolButton 中使用HTML 格式。例如在这张图片中,我应该在“Sara”和“Online”中创建QToolButton

这是我的代码:

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 格式。

如何解决?

我还在QToolButton 中使用了布局,但它显示为空框。

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

【问题讨论】:

标签: html c++ qt


【解决方案1】:

根据here提到的答案

如果不继承 QToolButton 并覆盖paintEvent,我认为这是不可能的。但你可以试试这样的:

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

【讨论】:

  • 非常感谢您的回答,虽然我想在 QToolButton 中创建多行。这样做对我没有帮助。
猜你喜欢
  • 1970-01-01
  • 2013-12-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-01
相关资源
最近更新 更多