in dem Beispiel wird ein QLineEdit durch einen QPushButton aktiviert. Das QLineEdit Widget sollte automatisch fokusiert sein. Das funktioniert auch, aber nur wenn der Button nicht gelöscht wird. Wird der QPushButton gelöscht, dann hat .setFocus() keine Wirkung. Warum bekommt das QLineEdit keinen Fokus, wenn ich vorher den Button lösche (in der Art und Weise wie das geschieht)?
Es funktionier auch, wenn ich den Button erst nach dem .setFocus() Befehl lösche - leider ist das für das tatsächliche Programm keine Option.
Ich bin für alle Idee/Tipps dankbar!
Torsten
Code: Alles auswählen
#!/usr/bin/python
# -*- coding: utf-8 -*-
from PyQt4.QtGui import *
class Form(QWidget):
def drawtextBox(self):
self.answerLine = QLineEdit()
self.textBox = QHBoxLayout()
self.textBox.addWidget(self.answerLine)
self.mainLayout.addLayout(self.textBox)
def drawcontinueBox(self):
self.submitButton = QPushButton("Continue")
self.continueBox = QHBoxLayout()
self.continueBox.addWidget(self.submitButton)
self.mainLayout.addLayout(self.continueBox)
self.submitButton.clicked.connect(self.submitContinue)
## Routine to Remove a Component ("which" = which BoxLayout)
def removeItem(self, which):
for cnt in reversed(range(which.count())):
widget = which.takeAt(cnt).widget()
if widget is not None:
widget.deleteLater()
def __init__(self, parent=None):
super(Form, self).__init__(parent)
self.mainLayout = QVBoxLayout(self)
self.drawcontinueBox()
self.setLayout(self.mainLayout)
self.setWindowTitle("Test")
def submitContinue(self):
self.removeItem(self.continueBox) ## Here is the problem
self.drawtextBox()
self.answerLine.setFocus()
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
screen = Form()
screen.show()
sys.exit(app.exec_())