QGraphicsView窃取专注于在OSX上悬停?

时间:2015-05-26 23:05:06

标签: qt

我有一个带有各种QDockWidgets的QMainWindow。其中一个QDockWidgets有一个QDoubleSpinBox。中心有一个QGraphicsView。

当用户正在编辑SpinBox中的值,然后将鼠标悬停在QGraphicsView上时,它会窃取焦点。这是通过在SpinBox的focusOutEvent()

期间检查QAp​​plication :: focusWidget()来确认的。

添加以下代码可以消除焦点窃取,确认焦点正在转移到QGraphicsView。

void OtherQGraphicsView::mouseMoveEvent(QMouseEvent *event) {
    QWidget *w = QApplication::focusWidget();
    if (w == this) {
        event->accept();
    }
}

据我了解,Qt不支持焦点跟随悬停模型。 QGraphicsView如何才能通过mouseMoveEvent获得焦点?

我是否应该对SpinBox做些什么来防止盗窃?

例如,只是从Qt创建者内置示例中加载DiagramScene示例。当鼠标悬停在主面板上时,顶部的字体选择器将失去焦点。

编辑:这发生在OSX(Yosemite)上,但不发生在Windows(8.1)

编辑2:发生违规事件时的堆栈跟踪:

0   NumberEdit::focusOutEvent(QFocusEvent *)    inspector.cpp   123 0x10003cc00 
1   QWidget::event(QEvent *)    QWidget::event(QEvent*)     0x1001a8add 
2   QAbstractSpinBox::event(QEvent *)   QAbstractSpinBox::event(QEvent*)        0x100252bc9 
3   QApplicationPrivate::notify_helper(QObject *, QEvent *) QApplicationPrivate::notify_helper(QObject*, QEvent*)       0x10016932b 
4   QApplication::notify(QObject *, QEvent *)   QApplication::notify(QObject*, QEvent*)     0x10016c648 
5   QCoreApplication::notifyInternal(QObject *, QEvent *)   QCoreApplication::notifyInternal(QObject*, QEvent*)     0x100fe1d83 
6   QApplicationPrivate::setFocusWidget(QWidget *, Qt::FocusReason) QApplicationPrivate::setFocusWidget(QWidget*, Qt::FocusReason)      0x1001670ce 
7   QWidget::setFocus(Qt::FocusReason)  QWidget::setFocus(Qt::FocusReason)      0x1001a4809 
8   QApplicationPrivate::giveFocusAccordingToFocusPolicy(QWidget *, QEvent *, QPoint)   QApplicationPrivate::giveFocusAccordingToFocusPolicy(QWidget*, QEvent*, QPoint)     0x10016d348 
9   QApplication::notify(QObject *, QEvent *)   QApplication::notify(QObject*, QEvent*)     0x10016bef1 
10  QCoreApplication::notifyInternal(QObject *, QEvent *)   QCoreApplication::notifyInternal(QObject*, QEvent*)     0x100fe1d83 
11  QApplicationPrivate::translateRawTouchEvent(QWidget *, QTouchDevice *, QList<QTouchEvent::TouchPoint> const&, unsigned long)    QApplicationPrivate::translateRawTouchEvent(QWidget*, QTouchDevice*, QList<QTouchEvent::TouchPoint> const&, unsigned long)      0x10016ef2b 
12  QWidgetWindow::event(QEvent *)  QWidgetWindow::event(QEvent*)       0x1001c2eb5 
13  QApplicationPrivate::notify_helper(QObject *, QEvent *) QApplicationPrivate::notify_helper(QObject*, QEvent*)       0x10016932b 
14  QApplication::notify(QObject *, QEvent *)   QApplication::notify(QObject*, QEvent*)     0x10016c648 
15  QCoreApplication::notifyInternal(QObject *, QEvent *)   QCoreApplication::notifyInternal(QObject*, QEvent*)     0x100fe1d83 
16  QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::TouchEvent *)  QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::TouchEvent*)       0x10081eb09 
17  QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *)    QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent*)     0x10081bc69 
18  QWindowSystemInterface::sendWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>)   QWindowSystemInterface::sendWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>)       0x1008092da 
19  QCocoaEventDispatcherPrivate::postedEventsSourceCallback(void *)    QCocoaEventDispatcherPrivate::postedEventsSourceCallback(void*)     0x1033b0411 
20  __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__  __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__      0x7fff895e87c1  
21  __CFRunLoopDoSources0   __CFRunLoopDoSources0       0x7fff895da94d  
22  __CFRunLoopRun  __CFRunLoopRun      0x7fff895d9f7f  
23  CFRunLoopRunSpecific    CFRunLoopRunSpecific        0x7fff895d9998  
24  RunCurrentEventLoopInMode   RunCurrentEventLoopInMode       0x7fff880a27df  
25  ReceiveNextEventCommon  ReceiveNextEventCommon      0x7fff880a245e  
26  _BlockUntilNextEventMatchingListInModeWithFilter    _BlockUntilNextEventMatchingListInModeWithFilter        0x7fff880a239b  
27  _DPSNextEvent   _DPSNextEvent       0x7fff8b739a6d  
28  -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]    -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]        0x7fff8b739220  
29  -[NSApplication run]    -[NSApplication run]        0x7fff8b72d0c3  
30  QCocoaEventDispatcher::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) QCocoaEventDispatcher::processEvents(QFlags<QEventLoop::ProcessEventsFlag>)     0x1033af2fd 
31  QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>)     0x100fdf37d 
32  QCoreApplication::exec()    QCoreApplication::exec()        0x100fe235a 
33  main    main.cpp    100 0x100004b82 
34  start   start       0x100004014 

0 个答案:

没有答案