Results 1 to 5 of 5

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

Threaded View

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

    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
  •  
Qt is a trademark of The Qt Company.