PyQt Programm aktiv starten
Verfasst: Freitag 19. Februar 2010, 13:38
Hallo zusammen
Ich habe ein Programm (aus "Rapid Gui Programming with PyQt") geschrieben:
Wenn ich das aus dem Terminal mit
$ calc.pyw
aufrufe, bleibt der Fokus leider im Terminal und ich muss erst UMSTÄNDLICH die Maus bemühen und das kleine Widget aktivieren damit ich tippen kann. Wie kann ich erreichen, dass das Widget sofort aktiv ist, wenn ich das Programm ausführe?
Vielen Dank für hilfreiche Beiträge.
Ich habe ein Programm (aus "Rapid Gui Programming with PyQt") geschrieben:
Code: Alles auswählen
#!/usr/bin/pythonw
#How to set the focus to the application?
from __future__ import division
import sys
from math import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class Form(QDialog):
def __init__(self, parent=None):
super(Form, self).__init__(parent)
self.browser = QTextBrowser()
self.lineedit = QLineEdit("Type an expression and press Enter")
self.lineedit.selectAll()
layout = QVBoxLayout()
layout.addWidget(self.lineedit)
layout.addWidget(self.browser)
self.setLayout(layout)
self.lineedit.setFocus()
#widget: self.lineedit,
#SIGNAL: returnPressed(),
#slot: self.updateUi 'of Form'.
self.connect(self.lineedit, SIGNAL("returnPressed()"),
self.updateUi)
self.setWindowTitle("Calc.pyw")
def updateUi(self):
#catch all exception
try:
text = unicode(self.lineedit.text())
self.browser.append("%s = <b>%s</b>" % (text, eval(text)))
except:
self.browser.append(
"<font color=red>%s is invalid!</font>" % text)
app = QApplication(sys.argv)
form = Form()
app.setActiveWindow(form)
#Does not work to set the focus on the application.
#form.setFocus()
form.show()
app.exec_()
$ calc.pyw
aufrufe, bleibt der Fokus leider im Terminal und ich muss erst UMSTÄNDLICH die Maus bemühen und das kleine Widget aktivieren damit ich tippen kann. Wie kann ich erreichen, dass das Widget sofort aktiv ist, wenn ich das Programm ausführe?
Vielen Dank für hilfreiche Beiträge.