Qt QGraphicsView抢断关注OSX上的悬停?
我有一个包含各种Qdock小部件的QMainWindow。其中一个QdockWidget具有QDoubleSpinBox。中间有一个QGraphicsView 当用户在SpinBox中编辑一个值,然后将鼠标悬停在QGraphicsView上时,它会窃取焦点。这可以通过在SpinBox的focusOutEvent()期间检查QApplication::focusWidget()来确认 添加以下代码可以消除焦点窃取,从而确认焦点正在移动到QGraphicsViewQt QGraphicsView抢断关注OSX上的悬停?,qt,Qt,我有一个包含各种Qdock小部件的QMainWindow。其中一个QdockWidget具有QDoubleSpinBox。中间有一个QGraphicsView 当用户在SpinBox中编辑一个值,然后将鼠标悬停在QGraphicsView上时,它会窃取焦点。这可以通过在SpinBox的focusOutEvent()期间检查QApplication::focusWidget()来确认 添加以下代码可以消除焦点窃取,从而确认焦点正在移动到QGraphicsView void OtherQGraphi
void OtherQGraphicsView::mouseMoveEvent(QMouseEvent *event) {
QWidget *w = QApplication::focusWidget();
if (w == this) {
event->accept();
}
}
据我所知,Qt不支持focusfollowshover模型。QGraphicsView如何通过mouseMoveEvent获得焦点
我应该对SpinBox做些什么来防止偷窃发生
例如,只需从Qt creator内置示例加载DiagramScene示例即可。当鼠标悬停在主面板上时,顶部的字体选择器将失去焦点
编辑:这发生在OSX(约塞米蒂)上,而不是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 NumberEdit::focusOutEvent(QFocusEvent*)inspector.cpp 123 0x10003cc00
1 QWidget::event(QEvent*)QWidget::event(QEvent*)0x1001a8add
2 QAbstractSpinBox::事件(QEvent*)QAbstractSpinBox::事件(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常量和,无符号长)QApplicationPrivate::translateRawTouchEvent(QWidget*,QTouchDevice*,QList常量和,无符号长)0x10016ef2b
12 QWidgetWindow::事件(QEvent*)QWidgetWindow::事件(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(QWindowsSystemInterfacePrivate::TouchEvent*)QGuiApplicationPrivate::processTouchEvent(QWindowsSystemInterfacePrivate::TouchEvent*)0x10081eb09
17 QGuiApplicationPrivate::ProcessWindowsSystemEvent(QWindowsSystemInterfacePrivate::WindowsSystemEvent*)QGuiApplicationPrivate::ProcessWindowsSystemEvent(QWindowsSystemInterfacePrivate::WindowsSystemEvent*)0x10081bc69
18 QWindowsSystemInterface::SendWindowsSystemEvents(QFlags)QWindowsSystemInterface::SendWindowsSystemEvents(QFlags)0x1008092da
19 QCocoaEventDispatcherPrivate::postedEventsSourceCallback(void*)QCocoaEventDispatcherPrivate::postedEventsSourceCallback(void*)0x1033b0411
20 \uuuuCFRUNLOOP\uuuuuuuuuuuuuuuuuuuuCFRUNLOOP\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuCFRUNLOOP\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
21 uuu CFRunLoopDoSources0 uuu CFRunLoopDoSources0 0x7fff895da94d
22 \uuuu CFRunLoopRun \uuuu CFRunLoopRun 0x7fff895d9f7f
23 cfrunloopspecific cfrunloopspecific 0x7fff895d9998
24 RunCurrentEventLoopInMode RunCurrentEventLoopInMode 0x7fff880a27df
25 ReceiveNextEventCommon ReceiveNextEventCommon 0x7fff880a245e
26 _blockuntinexteventmatchinglistinmodewithfilter _blockuntinexteventmatchinglistinmodewithfilter0x7FFF880A239B
27 _dpsnextent _dpsnextent0x7FFF8B739A6D
28-[NSApplication NextEventMachingmask:untilDate:inMode:dequeue:][NSApplication NextEventMachingmask:untilDate:inMode:dequeue:]0x7fff8b739220
29-[NSApplication run]-[NSApplication run]0x7fff8b72d0c3
30 QCocoaEventDispatcher::processEvents(QFlags)QCocoaEventDispatcher::processEvents(QFlags)0x1033af2fd
31 QEventLoop::exec(QFlags)QEventLoop::exec(QFlags)0x100fdf37d
32 QCoreApplication::exec()QCoreApplication::exec()0x100fe235a
33 main.cpp 100 0x100004b82
34开始0x10000414
听起来像是一个bug。我会在Qt bugtracker中报告一个这样的bug,举一个最小的例子。你能用最小的代码重现这个问题吗?这将证明它不是由您的一些代码引起的,这些代码是您没有想到的。qgraphicscene
是否包含一些可聚焦项?在该方法中设置断点并重现问题。当程序停止时,检查调用堆栈是否包含任何干扰。将此调用堆栈粘贴到您的问题。堆栈跟踪中唯一奇怪的是从未调用QGUI应用程序私有::processTouchEventQWindow::touchEvent(),并且焦点小部件的Qt::WA_AcceptTouchEvents为false。