[Solved] Qt- Trouble changing color of Line
-
wrote on 22 May 2012, 22:36 last edited by
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!!
-
wrote on 22 May 2012, 23:33 last edited by
What kind of lines?
-
wrote on 23 May 2012, 05:04 last edited by
You need to provide some code/image related to what you are trying to achieve.
-
wrote on 23 May 2012, 18:10 last edited by
-
wrote on 27 May 2012, 13:00 last edited by
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
-
wrote on 29 May 2012, 15:18 last edited by
Great. Thanks, Sam!!
-
wrote on 29 May 2012, 16:55 last edited by
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.
-
wrote on 30 May 2012, 09:35 last edited by
If it is going to be only Horizontal or Vertical lines, would suggest to consider QFrame class (Horizontal & Vertical lines comes with Qt Creator Toolbox).
1/8