Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

how does the fonction update() of a derived class work?

$
0
0
what I want is simple: click on a widget and draw a point where we click. for this, I create a class who inherits the class QWidget and I overwrite the fonction paintEvent and mousePressEvent and in this class, there is a data QPoint(posMouse) to memorize the position of the mouse void MyWidget::paintEvent(QPaintEvent *event) { //draw a point with a painter according to the posMouse } void MyWidget::mousePressEvent(QMouseEvent *event) { if(event->button() == Qt::LeftButton) { posMouse = event->pos(); update(); //doesn’t work } } my problem is: i find that the update() in the fonction mousePressEvent doesn’t work. it means that when I click on the MyWidget, I cant see the point. if I want to see it, I must change the focus of the mainwindow. for example I can open another window and click back to my mainwindow of Qt, then I can see the point. in fact, as we know, the fonction update() is used to call the fonction paintEvent, but here, obviously it doesn’t work. I think that this is because the update() here is a fonction of base class, so it call the paintEvent of base class, not my new paintEvent. (Am I right???) can u help me plz? thx in advance

Viewing all articles
Browse latest Browse all 13965

Trending Articles