-1

i made custom widget with two labels inside. First one is for showing chosen color and second one is just for displaing text. I want to make hover effect. I tried different approaches but all of them ends with the same result. Hover works but only for those two block seperately (like in the pictures below:)

enter image description here enter image description here

I want to highlight whole block as one (the red rectangle area showed below):

enter image description here

I tried to achieve that inside of custom widget constructor with:

this->setStyleSheet(":hover{ background-color: rgba(0,20,100,0.5); }");

Also i tried to add QFrame object to my ui and replace that with my custom widget. Both methods are not working. I found that topic: Set a StyleSheet for a whole widget in Qt

where someone managed to make it with:

Finally I solved the problem creating a QFrame inside the main QWidget and setting the StyleSheet of that QFrame.

I tried that approach but i'm not sure if i applied that correctly (propably not since that's still not working). Can someone help me with that?

Tojmak
  • 155
  • 1
  • 7

1 Answers1

0

I has a same problem, i guess your solution is simplest. btw the right decision is overrided EventFilter() method for your custom widget. like this:

bool CustomWidget::eventFilter(QObject *obj, QEvent *event)
{
    if (obj ==  ui->pushButton) {
          QEvent::Type type = event->type();
          if  (type == QEvent::HoverLeave) {
 
             qDebug()<<"No";
 
          } else if (type == QEvent::HoverEnter) {
 
             qDebug()<<"YES";
 
          }else if (type == QEvent::MouseButtonPress) {
            qDebug()<<"enter";
          }
      }
 
      return QWidget::eventFilter(obj, event);
}