无法在 QView 中的 QPixMap(image) 中获取触摸输入
我在 QWidget 中有一个 QScene 对象,在 QWidget 中有一个 QGraphicsView。我将图像转换为 QPixMap,将其作为元素提供给 QScene,并在 QGraphicsView 类中定义触摸事件。在 QGraphicsView 的创建者方法中,我启用了触摸事件:
viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
并且我通过重写 ViewPortEvent 方法来管理触摸事件:
bool DicomView::viewportEvent(QEvent *event)
{
if(event->type() == QEvent::TouchBegin)
{
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
.......
return QGraphicsView::viewportEvent(event);
}
PS:DicomView 是 QGraphicsView 的类型。
我的问题是,当我运行应用程序时,我可以从视图获取触摸输入,但是当到达 QView 时无法从 QPixMap 获取触摸输入。我尝试将方法放入 QScene 而不是 QGraphicsView 中,但 QScene 没有 ViewPortEvent 方法。我该怎么办?
I have a QScene object in QWidget and inside QWidget I have QGraphicsView. I convert images to QPixMap give it to QScene as an element and I defined touch events in QGraphicsView class. In QGraphicsView's creator method I enabled touch events with:
viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
and I am managing touch event by overriding ViewPortEvent method:
bool DicomView::viewportEvent(QEvent *event)
{
if(event->type() == QEvent::TouchBegin)
{
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
.......
return QGraphicsView::viewportEvent(event);
}
PS: DicomView is type of QGraphicsView.
My problem is when I run the application I can get the touch inputs from the view but when get to QView can not get touch inputs from QPixMap. I tried putting the methods inside QScene instead of QGraphicsView but QScene does not have a ViewPortEvent method. What am I supposed to do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论