PDA

View Full Version : How can I use events for widgets that are not visible by default?



Hossein
24th October 2015, 18:11
Hello everyone.
I am trying to use lets say click event on a QLabel ( or a QSpinBox, when a user presses `Enter`, it e.g executes a method etc).
I know in the hierarchy it gets it (from base widget class? )
Now I have read everywhere that whenever I want to use events that are not visible by default, I have to make a custom label class from inhering from QLabel, and then override that specific event.
This is cumbersome, and time consuming, suppose I have different widgets on my form, and for each of them I have to do this, and If the application has a complex GUI, I will not be able to use QtCreators designer which mostly I use, and I will be stuck with the hand-code everything!

Is there a workaround this limitation in Qt? why do you do when you encounter situations like this?
Is it not possible for the QtCreator to list the inherited events (signals) as well, and let the user use them ? would it not make it better ?
I would be grateful to know how I can get around this. I am stuck with simplistic GUI, that if I want to make it more complex, it makes me rewrite everything almost from scratch !

Thanks in advance

anda_skoa
24th October 2015, 19:26
suppose I have different widgets on my form, and for each of them I have to do this, and If the application has a complex GUI, I will not be able to use QtCreators designer which mostly I use, and I will be stuck with the hand-code everything!

You can always use your own widget subclasses in designer, that is what its "promote widget" functionality is for.

But you could also look into using an event filter: QObject::eventFilter.

Cheers,
_