Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Setting custom QGraphicsItem setAcceptedMouseButtons() to 0 giving error
Forum Updated to NodeBB v4.3 + New Features

Setting custom QGraphicsItem setAcceptedMouseButtons() to 0 giving error

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 5 Posters 777 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SlappyDanger
    wrote on last edited by
    #1

    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.

    jsulmJ 1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by Christian Ehrlicher
      #5

      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) or setAcceptedMouseButtons({})

      /edit2: https://codereview.qt-project.org/c/qt/qtbase/+/404042

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2
      • S SlappyDanger

        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.

        jsulmJ Online
        jsulmJ Online
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @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

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        S 1 Reply Last reply
        1
        • jsulmJ jsulm

          @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

          S Offline
          S Offline
          SlappyDanger
          wrote on last edited by
          #3

          @jsulm

          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?

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #4

            Hi,

            Can you show where in the documentation ?
            Might be some leftover from a previous version.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            S 1 Reply Last reply
            1
            • Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by Christian Ehrlicher
              #5

              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) or setAcceptedMouseButtons({})

              /edit2: https://codereview.qt-project.org/c/qt/qtbase/+/404042

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              2
              • SGaistS SGaist

                Hi,

                Can you show where in the documentation ?
                Might be some leftover from a previous version.

                S Offline
                S Offline
                SlappyDanger
                wrote on last edited by
                #6

                @SGaist

                I would be happy to, sir.

                eefc11d9-bcf3-4944-8ac2-678089684524-image.png

                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:

                d32c1216-f18e-42cd-b788-18f8832cce42-image.png

                Maybe I'm doing something wrong?

                SGaistS JonBJ 2 Replies Last reply
                0
                • S SlappyDanger

                  @SGaist

                  I would be happy to, sir.

                  eefc11d9-bcf3-4944-8ac2-678089684524-image.png

                  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:

                  d32c1216-f18e-42cd-b788-18f8832cce42-image.png

                  Maybe I'm doing something wrong?

                  SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #7

                  @SlappyDanger No you did not, as @Christian-Ehrlicher wrote, QFlag has become more restrictive.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  S 1 Reply Last reply
                  1
                  • SGaistS SGaist

                    @SlappyDanger No you did not, as @Christian-Ehrlicher wrote, QFlag has become more restrictive.

                    S Offline
                    S Offline
                    SlappyDanger
                    wrote on last edited by
                    #8

                    @SGaist @Christian-Ehrlicher

                    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.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #9

                      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.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      1
                      • S SlappyDanger

                        @SGaist

                        I would be happy to, sir.

                        eefc11d9-bcf3-4944-8ac2-678089684524-image.png

                        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:

                        d32c1216-f18e-42cd-b788-18f8832cce42-image.png

                        Maybe I'm doing something wrong?

                        JonBJ Online
                        JonBJ Online
                        JonB
                        wrote on last edited by
                        #10

                        @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.

                        S 1 Reply Last reply
                        1
                        • JonBJ JonB

                          @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.

                          S Offline
                          S Offline
                          SlappyDanger
                          wrote on last edited by
                          #11

                          @JonB thank you so much!

                          @SGaist I will do that, thank you!

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved