Keep lines drawn by drawPolyLine() function as an object?
Hi, I am making poly-lines on my
QPainter. I have an algorithm that detects when my mouse is over one of these poly-lines. What I want to achieve is to highlight the given poly-line (such as by changing the colour) so that the user understands that the poly-line can be selected. The problem is to change the colour of the poly-line I have to call
paintEvent()again which is highly inefficient as it redraws everything else. Is there any way I can create a poly-line object that is displayed in a
QWidgetand whose colour can be changed easily without calling
paintEvent()? I know I can use
QGraphicsItembut for that I will have to move my entire thing from
QGraphicsSceneand I would like to avoid that.
Is this what you're after?
QPainterPathcan work but I will still have to redraw it in
paintEvent()I am looking for something that I can change the colour of without calling
QWidget. Is it possible?
Is it possible?
Absolutely not. How is it supposed to be drawn if you intend to not draw it? It just can't happen.
JonB last edited by
As you said originally, if you want graphical objects you can manipulate individually you need to move to
QGraphicsItems. While you are painting on widgets, once you draw a line it's "gone", there is no object for you to access, and you need to redraw to recreate it.
need to move to QGraphicsItems
Or directly paint the prepared
QPainterPaths, although the graphics item is going to do that for you, so there's some convenience.