Unsolved Keep lines drawn by drawPolyLine() function as an object?
-
Hi, I am making poly-lines on my
QWidget
usingdrawPolyLine()
function ofQPainter
. 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 callQWidget
'spaintEvent()
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 aQWidget
and whose colour can be changed easily without callingpaintEvent()
? I know I can useQGraphicsItem
but for that I will have to move my entire thing fromQWidget
toQGraphicsView
-QGraphicsScene
and I would like to avoid that. -
Is this what you're after?
https://doc.qt.io/qt-5/qpainterpath.html -
@kshegunov Thanks,
QPainterPath
can work but I will still have to redraw it inpaintEvent()
I am looking for something that I can change the colour of without callingpaintEvent()
for theQWidget
. Is it possible? -
@CJha said in Keep lines drawn by drawPolyLine() function as an object?:
Is it possible?
Absolutely not. How is it supposed to be drawn if you intend to not draw it? It just can't happen.
-
@CJha
As you said originally, if you want graphical objects you can manipulate individually you need to move toQGraphicsItem
s. 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. -
@JonB & @kshegunov Thanks for clearing it up. I just wasn't sure if it is possible or not because I could not find any reference to any such thing anywhere.
-
@JonB said in Keep lines drawn by drawPolyLine() function as an object?:
need to move to QGraphicsItems
Or directly paint the prepared
QPainterPath
s, although the graphics item is going to do that for you, so there's some convenience.