2017-02-14 2 views
0

다음 코드를 고려하십시오. BeagleBone (libqt5widgets5 : armhf 5.7.1 + dfsg-3 + b1)에서 실행합니다. 그것은 화재 FocusInEvent 이벤트를 않습니다. QDialog를 줄 (***)의 QWidget으로 대체하면 작동이 멈 춥니 다. 왜?QWidget에 대한 포커스 이벤트 없음

다른 PyQt5 설치 (Cygwin을 사용하여 확인)에서 재현 할 수 없습니다.

[1]이, :focus don't work in PyQt (QT 5.7)가 [2] C++에서 같은 일이 어느 당신은 setFocusPolicy(Qt::FocusPolicy policy)를 호출하여는 QWidget 초점 이벤트를 수용 할 필요가 https://github.com/leshikus/qt-test

#!/usr/bin/python3 
# -*- coding: utf-8 -*- 

import sys 
from PyQt5.QtWidgets import QApplication, QWidget, QSlider, QCheckBox, QVBoxLayout, QMainWindow, QDialog 
from PyQt5.QtCore import Qt, QEvent 


class MyWidget(QSlider): 
    def __init__(self): 
     super().__init__() 

    def focusInEvent(self, event): 
     super().focusInEvent(event) 
     print('focusInEvent') 

    def focusOutEvent(self, event): 
     super().focusOutEvent(event) 
     print('focusOutEvent') 

    def eventFilter(self, source, event): 
     print("eventFilter", event.type(), source) 
     return super().eventFilter(source, event) 


if __name__ == '__main__': 

    app = QApplication(sys.argv) 

    w = QDialog() # got replaced with QWidget (***) 
    w.resize(300, 200) 
    w.move(30, 30) 

    layout = QVBoxLayout() 
    layout.setContentsMargins(0, 0, 0, 0) 
    layout.setSpacing(0) 

    s = MyWidget() 
    layout.addWidget(s) 
    w.setLayout(layout) 

    s.installEventFilter(s) 
    s.setFocus() 
    w.show() 

    sys.exit(app.exec_()) 
+0

사용할 수 있습니다 Dashboard.jspa). – ekhumoro

답변

1

작동하지 않을 수 있습니다 또는 관련되지 않을 수 있습니다

포커스 정책에 대한 자세한 내용은 C++ API을 확인하십시오. 당신이 버그/misfeature을 발견 한 경우에는

파이썬 별 설명서는 (https://bugreports.qt.io/secure/를 [적절한 버그 리포트를 만들]에 필요 PyQt4

+0

'w.setFocusPolicy (Qt.StrongFocus)를 추가하면 도움이되지 않습니다 – dataved

+0

MyWidget의 초기화 프로그램에서'self.setFocusPolicy (Qt.StrongFocus)'를 호출 해보십시오. – gortsu

+0

행운도 없습니다. 참고 다른 플랫폼에서는 버그가 재현되지 않습니다. – dataved