Hi,
I have some problem with clearing the previous points while drawing with draw(from,to).
I attached a sample project.
How can I clear the only changing area in the plot ?
Hüseyin
Printable View
Hi,
I have some problem with clearing the previous points while drawing with draw(from,to).
I attached a sample project.
How can I clear the only changing area in the plot ?
Hüseyin
When painting in XOR mode a second paint operation reverts the first one. ( google for XOR mode and you will find out how it works). Unfortunately all raster operations have been removed with Qt 4.
In the change log of Qt 4.5 I read, that raster operations have been reintroduced with Qt 4.5. I had no time to check it myself yet, but maybe painting in XOR mode is possible again. If true stuff like faster rubberbands or erasing of points/curves without complete replots could be implemented.
Uwe
Sorry it is so complicated for me using the XOR, and I don't know how to paint in the paintEvent() to the proper location.
I want to just fill the section with one solid color that I want to draw the curve.
I tired this, but cannot get the solution:
Code:
// ... if((start_index+changing_size) > plot_size){ // fragmented curve->draw(start_index,plot_size); curve->draw(0,(start_index+changing_size)-plot_size); } else{ QPainter painter; painter.begin(plot); painter.end(); curve->draw(start_index,start_index+changing_size); } // ...
Hüseyin
Your code doesn't work for many reasons:
a) You can paint to a widget outside of a paint event only on platforms, where Qt::WA_PaintOutsidePaintEvent is supported ( X11 ).
b) Curve points ( boundingRect() of a curve ) have a different coordinate system than QPainter. You need the canvas maps to translate between them.
c) You have to paint to the canvas - not to the plot widget.
d) You try to erase the complete curve and repaint only parts of it.
e) You try to paint behind the back of the canvas paint cache
...
Guess your intention is to speed up a "realtime" plot by painting only parts of a curve. This works when you are painting additional points, but as soon as you need to erase something you need the XOR mode.
I recommend to initialize your plot like in the data_plot example ( no paint cache ) and find a reasonable refresh rate (limiting replots by a QTimer) for your application.
Uwe
Thanks Uwe. It seems I can't draw out of the paintEvent() in windows. I tried it in winapi but needs some tune up.
Code:
void drawTest::plotData(void){ int changing_size = 10; int start_index = index; for(int i=0; i<changing_size; ++i){ data_y[index] = (qSin(index*0.1)*100+100) + (qrand() % 20); if(++index > plot_size) index = 0; } HWND hwnd = canvas->winId(); HDC hdc = GetDC(hwnd); static HPEN hpen_white = CreatePen(PS_SOLID,1,RGB(0,0,0)); SelectObject(hdc, hpen_white); RECT rec; rec.bottom = canvas->rect().height(); rec.top = 0; rec.left = data_x[start_index]; rec.right = data_x[start_index+changing_size]; FillRect(hdc, &rec, (HBRUSH) (COLOR_WINDOW+1) ); static HPEN hpen_black = CreatePen(PS_SOLID,1,RGB(0,0,0)); SelectObject(hdc, hpen_black); if(start_index+changing_size > plot_size){ for(int i=start_index; i<plot_size; ++i){ LineTo(hdc, data_x[i], data_y[i] ); } MoveToEx(hdc, data_x[0], data_y[0],NULL); for(int i=0; i<(start_index+changing_size)-plot_size; ++i){ LineTo(hdc, data_x[i], data_y[i] ); } } else{ MoveToEx(hdc, data_x[start_index], data_y[start_index],NULL); for(int i=0; i<changing_size; ++i){ LineTo(hdc, data_x[start_index+i], data_y[start_index+i] ); } } ReleaseDC(hwnd, hdc); }