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. How to capture the type of color and the type of drawing created with QPainter while I move the mouse (mouseEvent and eventFilter)

How to capture the type of color and the type of drawing created with QPainter while I move the mouse (mouseEvent and eventFilter)

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 498 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.
  • D Offline
    D Offline
    Domenico
    wrote on last edited by Domenico
    #1

    Hi everyone, can you help me with something that I can't solve ...

    What I would like to solve is to capture the type of color and the type of drawing while I move the mouse over a drawing drawn and colored with QPainter.

    It works like this:

    virtual bool eventfilter(QObject *obj, QEvent *event)
    {
    If(event->type() == QEvent::MouseMove)
    {
    QMouseEvent mouseEvent = dynamic_cast<QMouseEvent>(event) ;

    If(mouseEvent)
    {
    qDebug() <<"x: "<<mouseEvent.x()<<"y:" <<mouseEvent.y();
    }
    }
    }

    And this works for me by capturing the values ​​of the x and y coordinate axis. But to capture the type of color and type of design drawn with QPainter .. I can't find a solution. Can you help me? Maybe you write me with some similar examples? Thanks a lot to those who will help me```

    jsulmJ 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      What do you mean with the type of color ?
      like the RGB values?

      also "type of drawing" is also very broad.
      What info you expect to get from QPainter that would help you say "what type"

      Can you give some examples ?

      D 1 Reply Last reply
      1
      • mrjjM mrjj

        Hi
        What do you mean with the type of color ?
        like the RGB values?

        also "type of drawing" is also very broad.
        What info you expect to get from QPainter that would help you say "what type"

        Can you give some examples ?

        D Offline
        D Offline
        Domenico
        wrote on last edited by
        #3

        @mrjj
        Hi, I mean the color RGB or red, green, yellow, etc.

        While for the type of drawing I intend to capture if it is a line, a rectangle, a triangle, etc.

        For example, I draw a blue rectangle:

        painter.setPen(QPen (Qt :: blue, 1));
        painter.drawRect (1,1,10,10);
        

        So when I hover the mouse over this design, it will have to indicate to me that it is a blue rectangle.

        How do you create it in code? Thanks so much!

        mrjjM 1 Reply Last reply
        0
        • D Domenico

          @mrjj
          Hi, I mean the color RGB or red, green, yellow, etc.

          While for the type of drawing I intend to capture if it is a line, a rectangle, a triangle, etc.

          For example, I draw a blue rectangle:

          painter.setPen(QPen (Qt :: blue, 1));
          painter.drawRect (1,1,10,10);
          

          So when I hover the mouse over this design, it will have to indicate to me that it is a blue rectangle.

          How do you create it in code? Thanks so much!

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Domenico

          For color. You can paint on QImage instead.
          It allows access to the pixels.
          https://doc.qt.io/qt-5/qimage.html#pixel

          For the type.
          There is no way it can know you are over a blue rect as it just pixels for Qpainter.

          So for this to work, you have to keep track of the shapes you create and their locations.
          Like for line the end points. for a rect, the rect etc. and for triangle the 3 points.

          Then you can loop this list to see if mouse is over any of the shapes and then you know the type that way.

          To find rects, lines and triangles without keeping information would require some AI pattern recognition.

          D 1 Reply Last reply
          1
          • D Domenico

            Hi everyone, can you help me with something that I can't solve ...

            What I would like to solve is to capture the type of color and the type of drawing while I move the mouse over a drawing drawn and colored with QPainter.

            It works like this:

            virtual bool eventfilter(QObject *obj, QEvent *event)
            {
            If(event->type() == QEvent::MouseMove)
            {
            QMouseEvent mouseEvent = dynamic_cast<QMouseEvent>(event) ;

            If(mouseEvent)
            {
            qDebug() <<"x: "<<mouseEvent.x()<<"y:" <<mouseEvent.y();
            }
            }
            }

            And this works for me by capturing the values ​​of the x and y coordinate axis. But to capture the type of color and type of design drawn with QPainter .. I can't find a solution. Can you help me? Maybe you write me with some similar examples? Thanks a lot to those who will help me```

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5
            This post is deleted!
            1 Reply Last reply
            0
            • mrjjM mrjj

              @Domenico

              For color. You can paint on QImage instead.
              It allows access to the pixels.
              https://doc.qt.io/qt-5/qimage.html#pixel

              For the type.
              There is no way it can know you are over a blue rect as it just pixels for Qpainter.

              So for this to work, you have to keep track of the shapes you create and their locations.
              Like for line the end points. for a rect, the rect etc. and for triangle the 3 points.

              Then you can loop this list to see if mouse is over any of the shapes and then you know the type that way.

              To find rects, lines and triangles without keeping information would require some AI pattern recognition.

              D Offline
              D Offline
              Domenico
              wrote on last edited by
              #6

              Hi @mrjj ,

              I try to understand on QImage. for now I have implemented it on QPicture and I don't know if you can capture the color type from QPicture functions. can you?

              yes it is true the complexity of understanding what type of design it is, I thought there is an easy way to capture the type of design. maybe if anyone knows how to do it. would be very helpful.

              thank you very much. I await other solutions

              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