查看完整版本: [--
怎么获取鼠标在图片上的坐标
--]
QTCN开发网
->
Qt基础编程
->
怎么获取鼠标在图片上的坐标
[打印本页]
登录
->
注册
->
回复主题
->
发表主题
openlqh
2017-05-15 09:18
怎么获取鼠标在图片上的坐标
图片加载在 QLabel控件上。
重写了mousePressEvent,mouseReleaseEvent函数
但是用 pos()函数获取到的坐标点不对
void image::mousePressEvent(QMouseEvent *e)
{
setCursor(Qt::PointingHandCursor);
startPnt = e->pos();
endPnt = e->pos() ;
}
画出来的曲线和我鼠标点击的区域有差距。如果只是在窗口上用鼠标画图是正确的,但是在图片上画出来的坐标就不对了。
求指导。
大漠之鹰
2017-05-15 16:21
图片是不是放缩了?有没有进行偏移计算啊
openlqh
2017-05-15 16:33
大漠之鹰
:
图片是不是放缩了?有没有进行偏移计算啊
(2017-05-15 16:21)
谢谢回复啊,已经解决了。
int iWidth = pLabel->width();
int iHeight = pLabel->height();
px = px.scaled(iWidth, iHeight,Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
设置为QLabel的大小就可以了
查看完整版本: [--
怎么获取鼠标在图片上的坐标
--] [--
top
--]
Powered by
phpwind
v8.7
Code ©2003-2011
phpwind
Gzip disabled