How can I disable a Qt widget without changing its appearence

1k Views Asked by At

I have a Qt widget which has a layout and there are more widgets inside it. When I disable the widget the whole widget becomes little faded and no modifications are possible anymore. I want the features that comes with disabling a widget but I do not want it's appearance to change. Please let me know how this can be done.

Few ideas that comes to my mind:

  1. Rather disabling widget, capture all the events on the widget and do nothing
  2. Update style sheet for disabled state (not sure if possible)
1

There are 1 best solutions below

0
Benjamin T On

1. Capture events

Use QObject::installEventFilter() and QObject::eventfilter(). Keep in mind the way Qt dispatch GUI events, in particular children get events first. So you need to install the event filter recursively on all widgets and watch for QEvent::ChildAdded.

2. Using stylesheets

This is a not a good solution. Stylesheets tend to break QStyle mechanisms which may lead to side effects.

3. Use a QPixmap

Hide all the child widgets, render them to a QPixmap and draw the pixmap in the paintEvent.