Results 1 to 5 of 5

Thread: Clear previous points when using draw(from,to)

  1. #1
    Join Date
    Mar 2009
    Posts
    22
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Clear previous points when using draw(from,to)

    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
    Attached Files Attached Files

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,309
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Clear previous points when using draw(from,to)

    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

  3. #3
    Join Date
    Mar 2009
    Posts
    22
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Clear previous points when using draw(from,to)

    Quote Originally Posted by Uwe View Post
    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:
    Qt Code:
    1. // ...
    2. if((start_index+changing_size) > plot_size){ // fragmented
    3. curve->draw(start_index,plot_size);
    4. curve->draw(0,(start_index+changing_size)-plot_size);
    5. }
    6. else{
    7. QPainter painter;
    8. painter.begin(plot);
    9. painter.fillRect(curve->boundingRect().toRect(),QColor(Qt::white));
    10. painter.end();
    11. curve->draw(start_index,start_index+changing_size);
    12. }
    13. // ...
    To copy to clipboard, switch view to plain text mode 


    Hüseyin
    Attached Images Attached Images

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,309
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Clear previous points when using draw(from,to)

    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

  5. #5
    Join Date
    Mar 2009
    Posts
    22
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Clear previous points when using draw(from,to)

    Thanks Uwe. It seems I can't draw out of the paintEvent() in windows. I tried it in winapi but needs some tune up.

    Qt Code:
    1. void drawTest::plotData(void){
    2. int changing_size = 10;
    3. int start_index = index;
    4. for(int i=0; i<changing_size; ++i){
    5. data_y[index] = (qSin(index*0.1)*100+100) + (qrand() % 20);
    6. if(++index > plot_size) index = 0;
    7. }
    8.  
    9. QwtPlotCanvas * canvas = plot->canvas();
    10. HWND hwnd = canvas->winId();
    11. HDC hdc = GetDC(hwnd);
    12. static HPEN hpen_white = CreatePen(PS_SOLID,1,RGB(0,0,0));
    13. SelectObject(hdc, hpen_white);
    14. RECT rec;
    15. rec.bottom = canvas->rect().height();
    16. rec.top = 0;
    17. rec.left = data_x[start_index];
    18. rec.right = data_x[start_index+changing_size];
    19. FillRect(hdc, &rec, (HBRUSH) (COLOR_WINDOW+1) );
    20. static HPEN hpen_black = CreatePen(PS_SOLID,1,RGB(0,0,0));
    21. SelectObject(hdc, hpen_black);
    22. if(start_index+changing_size > plot_size){
    23. for(int i=start_index; i<plot_size; ++i){ LineTo(hdc, data_x[i], data_y[i] ); }
    24. MoveToEx(hdc, data_x[0], data_y[0],NULL);
    25. for(int i=0; i<(start_index+changing_size)-plot_size; ++i){ LineTo(hdc, data_x[i], data_y[i] ); }
    26. }
    27. else{
    28. MoveToEx(hdc, data_x[start_index], data_y[start_index],NULL);
    29. for(int i=0; i<changing_size; ++i){ LineTo(hdc, data_x[start_index+i], data_y[start_index+i] ); }
    30. }
    31. ReleaseDC(hwnd, hdc);
    32. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.