PDA

View Full Version : painting lines on the screen



neutrino
9th February 2013, 14:57
After trying many things and failed, i finally came here to do what i was trying.
I want to display lines which are stored in a file named "line.txt" in comma seperated values.
i have successfully read the values, but unable to draw them on the screen.
please help.

Santosh Reddy
9th February 2013, 15:48
QGraphicsLineItem can be used to create a line and then add it to a QGraphicsScene, and set that QGraphicsScene on to a QGraphicsView

neutrino
10th February 2013, 03:12
@santosh reddy:
do i have to reimplement the paintEvent method to use this?
If possible give an example code for this.

ChrisW67
10th February 2013, 03:55
No, QWidget::paintEvent() is not involved in what Santosh Reddy proposed as one solution to your vague requirement.

If you read the docs of the classes Santosh pointed out you'll find there are detailed descriptions of each class and links to the Graphics View Framework overview containing code snippets and whole examples/demos.

After "trying many things and failed" you should be able to better explain what you need, show what you tried, and explain why it does not meet your requirement.

neutrino
10th February 2013, 04:39
Ok , i tried again and succeeded this time.
method used:
read all the lines from the file into a qvector<qline> and used qpainter::drawlines() to draw the lines all at a time.

wysota
10th February 2013, 10:48
Ok , i tried again and succeeded this time.
method used:
read all the lines from the file into a qvector<qline> and used qpainter::drawlines() to draw the lines all at a time.

Just being curious --- so what have you tried "before" when you failed?

neutrino
10th February 2013, 14:56
i was trying to implement the functions described in the example "scribble" without understanding. Was doing random methods and hoping that something would work. now got another method to do the same(by using qimage for drawing widgets, and drawing the image via qpainter).
how to mark this thread as solved?
another question: is there any way to remove a line from the qimage other than drawing a line of the same color as the background.

wysota
10th February 2013, 15:45
another question: is there any way to remove a line from the qimage other than drawing a line of the same color as the background.
No, an image is an image -- a set of pixels with defined color values. It has no "history".

neutrino
11th February 2013, 03:29
ok. thanks