Important: Please read the Qt Code of Conduct -

Correct way to allow the user to highlight a region of interest on an image using the mouse

  • Greetings .

    I am implementing a custom widget that displays an image and has several buttons and other elements.

    I want to allow the user to highlight area of ​​interest in the image using the mouse (similar to that used in image management programs like MS Paint) . To this end, I have reimplemented methods :

    mousePressEvent ( QMouseEvent * event)
    mouseReleaseEvent ( QMouseEvent * event)
    mouseMoveEvent ( QMouseEvent * event)
    paintEvent ( QPaintEvent * event)

    Roughly what I do with these functions is to draw on the image , in the area marked with the mouse , a dotted rectangle (yellow in this case) . Actually , I think it generally works well , my question is on two related aspects :

    • Is what I am doing the best way to do the task I described above (ie , I paint one more rectangle on an image in an area marked with the mouse ) ?

    • I want the dotted lines that form the rectangle were less thick, saw a little more elongated and have more space between them.

    Here , when I speak of "thickness" I specifically mean the vertical thickness of the ( 2) horizontal lines and the horizontal thickness of the ( 2) vertical lines forming the sides of the rectangle .

    Thanks in advance for any help and / or suggestions.

Log in to reply