0

在 QT 中:我只想显示一个图标和一些文本,所以我使用 QPushButton。但是我怎样才能从中删除点击效果呢?

4

2 回答 2

2

您可以继承 QPushButton 并忽略除 Paint 事件之外的所有事件:

class IconLabel : public QPushButton {

...

bool IconLabel::event ( QEvent * e ) {
   if (e->type() == QEvent::Paint) {
      return QPushButton::event(e);
   }
   return true;
}

根据您的要求,可能需要让其他事件通过,例如,如果您想在 IconLabel 上使用工具提示:

   if (e->type() == QEvent::Paint ||
       e->type() == QEvent::ToolTip) {
      return QPushButton::event(e);
   }
于 2012-09-28T09:52:32.337 回答
2

我还没有尝试过这个解决方案,但看起来它应该可以工作。

从上面的链接复制

为标签使用富文本,例如:

lbl->setTextFormat(Qt::RichText);
lbl->setText("<img src=":/myimage.png">Hello!");
于 2012-09-28T10:23:27.233 回答