View Full Version : drawing lines using qpainter from file

9th February 2013, 08:22
I'm new to Qt programming and trying to build a gui program for a project. I need to draw multiple lines on the widget. The dimensions of the lines are stored in a file "line.txt". The file is correctly read by using qfile and qtextstream. I have also implemented the paintEvent() to draw one line. But when i'm trying to draw multiple lines, it shows no output. What's the problem and how to correct it? i'm attaching the code and the file "line.txt"

9th February 2013, 09:00
In future post, please post the relevant lines direct in the thread.

a) don't read the file every time paintEvent is called - which is quite often. Use the constructor and parse the file in a QList<QLine> or something similar.
b) Never call update or paint inside paintEvent!

9th February 2013, 10:03
There is this nice thing in Qt called QPicture, have a look at it.