2 回答
TA贡献1818条经验 获得超3个赞
您必须在出现后立即设置焦点,您可以使用 aQTimer::singleShot()或QMetaObject::invokeMethod():
1. QTimer::singleShot()
...
self.push_button = QtGui.QPushButton("go", self)
self.grid_layout.addWidget(self.create_controls_group(), 0, 1)
self.push_button.setDefault(True)
QtCore.QTimer.singleShot(0, self.push_button.setFocus)
2. QMetaObject::invokeMethod()
...
self.push_button = QtGui.QPushButton("go", self)
self.grid_layout.addWidget(self.create_controls_group(), 0, 1)
self.push_button.setDefault(True)
QtCore.QMetaObject.invokeMethod(self.push_button,
"setFocus",
QtCore.Qt.QueuedConnection)
TA贡献1789条经验 获得超10个赞
您可以尝试设置按钮Default属性:
self.push_button.setDefault(True)
self.push_button.setFocus()
添加回答
举报