Results 1 to 3 of 3

Thread: problem with QwtPlotCanvas::paintEvent

  1. #1
    Join Date
    Jan 2014
    Posts
    16
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default problem with QwtPlotCanvas::paintEvent

    hello all,
    i want to paint some thing (in this example , i do nothing) to a QwtPlotCanvas, so i subclass MyCanvas, in class MyCanvas constructor function , i configure object and implement paintEvent, However, the displaying QwtPlotCanvas is not correct as my except . Wrong result.JPG

    my code is listed as following.

    in mycanvas.h
    Qt Code:
    1. #ifndef MYCANVAS_H
    2. #define MYCANVAS_H
    3. #include <qwt_plot_canvas.h>
    4. #include<QPainter>
    5.  
    6. class MyCanvas:public QwtPlotCanvas
    7. {
    8. public:
    9. MyCanvas();
    10. void paintEvent(QPaintEvent *event);
    11. };
    12. #endif // MYCANVAS_H
    To copy to clipboard, switch view to plain text mode 
    in mycanvas.cpp
    Qt Code:
    1. #include "mycanvas.h"
    2.  
    3. MyCanvas::MyCanvas()
    4. {
    5. this->setBorderRadius( 15 );
    6. }
    7. void MyCanvas::paintEvent(QPaintEvent *event)
    8. {
    9. }
    To copy to clipboard, switch view to plain text mode 
    in mainwindow.h
    Qt Code:
    1. #define MAINWINDOW_H
    2. #include <QMainWindow>
    3. #include"mycanvas.h"
    4. namespace Ui {
    5. class MainWindow;
    6. }
    7.  
    8. class MainWindow : public QMainWindow
    9. {
    10. Q_OBJECT
    11. public:
    12. explicit MainWindow(QWidget *parent = 0);
    13. ~MainWindow();
    14. private:
    15. Ui::MainWindow *ui;
    16. MyCanvas * canvas;
    17. };
    18. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    in mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <qwt_plot_canvas.h>
    4.  
    5. MainWindow::MainWindow(QWidget *parent) :
    6. QMainWindow(parent),
    7. ui(new Ui::MainWindow),
    8. canvas(new MyCanvas)
    9. {
    10. ui->setupUi(this);
    11. ui->qwtPlot->setCanvas(canvas);
    12. }
    13. MainWindow::~MainWindow()
    14. {
    15. delete ui;
    16. }
    To copy to clipboard, switch view to plain text mode 
    any suggestions?

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

    Default Re: problem with QwtPlotCanvas::paintEvent

    Your code has to be:

    Qt Code:
    1. void MyCanvas::paintEvent(QPaintEvent *event)
    2. {
    3. QwtPlotCanvas::paintEvent( event );
    4.  
    5. // now do your stuff
    6. }
    To copy to clipboard, switch view to plain text mode 

    But I'm very sure that you are trying to do something the wrong way. In almost 100% of the use cases it is better to derive a new type of QwtPlotItem that can be attached to the plot scene.

    Uwe

  3. The following user says thank you to Uwe for this useful post:

    MickyJhon (31st January 2014)

  4. #3
    Join Date
    Jan 2014
    Posts
    16
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with QwtPlotCanvas::paintEvent

    Thank you very much, Uwe, Your advice is very useful .

    Quote Originally Posted by Uwe View Post
    Your code has to be:

    Qt Code:
    1. void MyCanvas::paintEvent(QPaintEvent *event)
    2. {
    3. QwtPlotCanvas::paintEvent( event );
    4.  
    5. // now do your stuff
    6. }
    To copy to clipboard, switch view to plain text mode 

    But I'm very sure that you are trying to do something the wrong way. In almost 100% of the use cases it is better to derive a new type of QwtPlotItem that can be attached to the plot scene.

    Uwe

Similar Threads

  1. Problem in paintEvent()
    By Niamita in forum Qt Programming
    Replies: 4
    Last Post: 10th May 2011, 10:46
  2. Replies: 3
    Last Post: 28th January 2010, 09:15
  3. Replies: 3
    Last Post: 25th August 2009, 15:24
  4. paintEvent problem
    By anafor2004 in forum Newbie
    Replies: 1
    Last Post: 29th June 2008, 14:18
  5. paintEvent problem
    By MoaLaiSkirulais in forum Qt Programming
    Replies: 5
    Last Post: 12th February 2008, 13:59

Tags for this Thread

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.