Question

In QT: I only want to show an icon and some text, so I use QPushButton. But how can I remove the click effect from it?

Was it helpful?

Solution

You can subclass QPushButton and ignore all events but the Paint event:

class IconLabel : public QPushButton {

...

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

Depending on your requirements, it might be necessary to let additional events pass through, like if you want to use a tooltip on your IconLabel:

   if (e->type() == QEvent::Paint ||
       e->type() == QEvent::ToolTip) {
      return QPushButton::event(e);
   }

OTHER TIPS

I haven't tried this solution but looks like it should work.

Copying from the link above

Use rich text for the label, e.g:

lbl->setTextFormat(Qt::RichText);
lbl->setText("<img src=":/myimage.png">Hello!");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top