Why does using setFocus on QCombobox have no response?

59 Views Asked by At

I tried using the setFocus method on QCombobox, but there was no response, just like I used the setFocus method on QLineEdit. I hope the focus can be on the QCombobox widget, just like when I move my mouse over it, it is highlighted. So, what should I do? Thanks. Here is my code:

class MyWindow(QMainWindow):
    def __init__(self):
        super(MyWindow, self).__init__()
        self.widget = QWidget()
        self.layout = QVBoxLayout()
        self.box = QComboBox()
        self.box.setFocusPolicy(Qt.FocusPolicy.WheelFocus)
        self.layout.addWidget(self.box)
        self.widget.setLayout(self.layout)
        self.setCentralWidget(self.widget)
        self.timer = QTimer()
        self.timer.timeout.connect(self.timeout)
        self.timer.start(3*1000)

    def timeout(self):
        print("timeout")
        self.box.setFocus()
0

There are 0 best solutions below