[Solved] Qt- Trouble changing color of Line
-
Hi,
I'm having trouble changing the color of Lines.
I tried playing with the color & border color.
None of them work when I preview or run my Gui.
Any ideas? Thanks!!
-
-
Not sure how this has to be done as QLine does not inherits from QObject. However you can create your own class that inherits from QLine and QObject, Have a look "here":http://stackoverflow.com/questions/5270546/qt-qline-class-extension
-
Great. Thanks, Sam!!
-
QLine is only the abstract concept of a line. Basically four integer values: x1,y1,x2,y2. The color, thickness, stroke etc. only comes in when a QPainter draws the line, in the QPen of the painter:
@
myPainter->setPen(QPen(Qt::red));
myPainter->drawLine(myLine);
@
The line class is "dumb" (plain-old-data), it doesn't paint itself, it doesn't even know it's a line that can be painted, it just stores the abstract data that describes a line.Hence I'm not sure whether extending QLine is a good idea for what you want to do... What do you want to do? Maybe creating an own line class, which knows how to draw itself (i.e. has a ::draw(QPainter* painter) function) is the better way to go.