C++ (Qt)Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget){ ui->setupUi(this); x = 10; y = 10;}void Widget::paintEvent( QPaintEvent *event ){ QPainter painter( this ); painter.setPen( QPen( Qt::black, 3 ) ); painter.drawPoint( QPoint( x, y ) );}Widget::~Widget(){ delete ui;} void Widget::mousePressEvent( QMouseEvent *mouseEvent ){ if ( mouseEvent->button() == Qt::LeftButton ) { x = mouseEvent->x(); y = mouseEvent->y(); update(); }}
C++ (Qt)namespace Ui{ class Widget;} class Widget : public QWidget{ Q_OBJECT public: Widget(QWidget *parent = 0); ~Widget(); protected: void paintEvent( QPaintEvent *event ); virtual void mousePressEvent( QMouseEvent *mouseEvent ); private: Ui::Widget *ui; int x; int y;};
C++ (Qt)void paintEvent( QPaintEvent *event, int x, int y );