Keep lines drawn by drawPolyLine() function as an object?
-
Hi, I am making poly-lines on my
QWidgetusingdrawPolyLine()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 aQWidgetand whose colour can be changed easily without callingpaintEvent()? I know I can useQGraphicsItembut for that I will have to move my entire thing fromQWidgettoQGraphicsView-QGraphicsSceneand I would like to avoid that. -
Hi, I am making poly-lines on my
QWidgetusingdrawPolyLine()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 aQWidgetand whose colour can be changed easily without callingpaintEvent()? I know I can useQGraphicsItembut for that I will have to move my entire thing fromQWidgettoQGraphicsView-QGraphicsSceneand I would like to avoid that.Is this what you're after?
https://doc.qt.io/qt-5/qpainterpath.html -
Is this what you're after?
https://doc.qt.io/qt-5/qpainterpath.html@kshegunov Thanks,
QPainterPathcan 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? -
@kshegunov Thanks,
QPainterPathcan 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.
-
@kshegunov Thanks,
QPainterPathcan 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
As you said originally, if you want graphical objects you can manipulate individually you need to move toQGraphicsItems. 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. -
@CJha
As you said originally, if you want graphical objects you can manipulate individually you need to move toQGraphicsItems. 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. -
@CJha
As you said originally, if you want graphical objects you can manipulate individually you need to move toQGraphicsItems. 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 said in Keep lines drawn by drawPolyLine() function as an object?:
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.