Setting custom QGraphicsItem setAcceptedMouseButtons() to 0 giving error
-
In the documentation for QGraphicsItems and setAcceptedMouseButtons, it says to use
setAcceptedMouseButtons(0);
in order to disable all mouse button events.
However, it's not working. It's giving me a conversion error from 'int' to 'Qt::MouseButtons'
I'm doing it in the GraphicsItem's constructor.
-
The o did not tell us that he's using Qt6 - there QFlags is more restrictive and does not allow a conversion from int. Will push a documentation fix.
/edit: the solution is to use
setAcceptedMouseButtons(Qt::NoButton)
orsetAcceptedMouseButtons({})
/edit2: https://codereview.qt-project.org/c/qt/qtbase/+/404042
-
@SlappyDanger said in Setting custom QGraphicsItem setAcceptedMouseButtons() to 0 giving error:
It's giving me a conversion error from 'int' to 'Qt::MouseButtons'
Then why don't you pass what the method expects? In your case you should pass Qt::NoButton
-
That works, but what worries me is that the documentation is telling me to do something that doesn't work.
I'm a very raw beginner to all of this, learning as I go. It's really frustrating to find stuff like this because if the official documentation is telling me incorrect information, what am I supposed to do?
-
Hi,
Can you show where in the documentation ?
Might be some leftover from a previous version. -
The o did not tell us that he's using Qt6 - there QFlags is more restrictive and does not allow a conversion from int. Will push a documentation fix.
/edit: the solution is to use
setAcceptedMouseButtons(Qt::NoButton)
orsetAcceptedMouseButtons({})
/edit2: https://codereview.qt-project.org/c/qt/qtbase/+/404042
-
I would be happy to, sir.
The above is from the QGraphicsItem wiki page, found here: https://doc.qt.io/qt-5/qgraphicsitem.html#setAcceptedMouseButtons
I was trying to implement that inside my custom QGraphicsItem constructor, like so:
Maybe I'm doing something wrong?
-
@SlappyDanger No you did not, as @Christian-Ehrlicher wrote, QFlag has become more restrictive.
-
Thank you gentlemen!
I will make sure to include that I am using QT 6 in the future.
Should I continue to post here or should I pose all questions I have in the QT 6 side of things? I will be unsure if it's a QT 6 specific issue for most of the things i'm likely to run into, though.
-
In the long run, the Qt 6 sub-forum should be merged back into this one. However for the time being it's a good idea to post there so it makes things clearer.
-
@SlappyDanger said in Setting custom QGraphicsItem setAcceptedMouseButtons() to 0 giving error:
The above is from the QGraphicsItem wiki page, found here: https://doc.qt.io/qt-5/qgraphicsitem.html#setAcceptedMouseButtons
Note that you are using the Qt5 doc page for your Qt6 work, e.g. here you should be looking at https://doc.qt.io/qt-6/qgraphicsitem.html#setAcceptedMouseButtons
In this case the Qt versions did not differ on your issue, but beware for the future.