I am trying to implement mouse events, and the attached code works OK on a QDialog derived application. Why is it not working on a QWidget derived application?
I am trying to implement mouse events, and the attached code works OK on a QDialog derived application. Why is it not working on a QWidget derived application?
Not sure what you are trying to do, but why do you not want mousePressEvent() to be called?
You have quite some code in that method, so not getting it called sounds like the opposite of what you would want.
Cheers,
_
I was trying to understand how events, specific events like mouse and kb events and signals work. So I made the simplest possible application. I want to use this to do a pop up menu on another widget.
Do you have any other way to do it? From a conceptual point of view, this should work. Usually, when something simple like this does not work, I am not understanding something funndamental.
Narada
I guess it depends on what your goal is.
If you goal was to bypass the event handling of QWidget then yes this is how it works.
But the thread's title suggests that you wanted mousePressEvent to be called, which bypassing the necessary implementation in QWidget will make impossible, conceptually and actually.
So maybe you could clarify if you wanted to bypass the event widget event handling and are surprised that is actually worked, or of you intended to implement the mouse press event handler and think it should miraculously work even if you bypass the code that calls it.
Cheers,
_
Actually, I didn't mean to bypass the event handling of the QWidget. I simply wanted to use the event. The way I have used it is typical in many of the examples in the Qt books. The funny thing is instead of QWidget, if I use QDialog with exactly the same code, it works.
But you do
You bypass the implementation of QWidget::event(), which contains the type switch that calls the specific virtual function in QWidget.
Maybe the mousePressEvent() override, I doubt these examples also bypass the very method that makes the calls to this methods.
Interesting, that should not work either.
Maybe it was not "exactly the same code"?
Cheers,
_
Narada (5th April 2016)
Hello anda_skoa,
Thanks for sticking with the thread until I resolved the issue.
You are correct. I took the event() override out, and it works now. My QDialog implementation did not have that override, and that is why it worked.
One more step further in my learning how event(), mousePressEvent() ( and others), and signals interact with each other.
If there is a good discussion on these three areas I would be happy to read it.
Thank you again.
Narada
Bookmarks