Solved Why can't I draw a line with mouse moving?
-
Excuse me, I'm not sure what you mean. Could you please help me modify the code ?
-
@Geng.Y
addrepaint()
in theViewWidget::mouseReleaseEvent()
changemouthPressEvent
tomousePressEvent
, so doesmouthMoveEvent
andmouthReleaseEvent
to see if it works -
As @Flotisable say, you are not overriding the functions as they are named
something elsevoid mouthPressEvent(QMouseEvent *event);
void mouthMoveEvent(QMouseEvent *event);
void mouthReleaseEvent(QMouseEvent *event);That is actually mouse and not mouth in front.
-
@Flotisable Thank you very much and it works!
-
I have mistaken mouth and mouse and it works now. But I'm still puzzled why I can't see the output of coordinates of mouse.
-
@Geng.Y
You mean
std::cout<<event->pos().x()<<' '<<event->pos().y()<<std::endl;they should show in Creator ?
In Application output panel -
@Geng.Y
You may use qDebug()<<event->pos() to show them on qt-creator.
If you want to show the coordinates of mouse on view, you may use QTooltip to show them. I found that it was quite useful to show them. -
@mrjj Thank you!
-
@mrjj I‘m using vs2010, how to show the coordinates?
-
@Geng.Y
Hi
Sorry I dont know visual Studio the IDE well enough.
I use only the compiler in Creator. -
@mrjj Thank you very much!
-
@Geng.Y
As suggested you can use the tooltip string
http://doc.qt.io/qt-5/qwidget.html#toolTip-prop
you can then see it directly on the app.