1
我正在學習PySide,我似乎無法得到QLineEdit
出現。我最好的猜測是因爲QTextEdit
被設置爲主窗口小部件並將其覆蓋。這裏是我的代碼:PySide QLineEdit沒有出現
#!/usr/bin/python
import sys
from PySide import QtGui
class Window(QtGui.QMainWindow):
def __init__(self):
super(Window, self).__init__()
self.initUI()
def initUI(self):
self.setWindowTitle("A Text Editor")
self.setGeometry(300,1000,500,500)
self.fileName = QtGui.QLineEdit('File Name')
self.fileName.resize(self.fileName.sizeHint())
self.text = QtGui.QTextEdit()
self.setCentralWidget(self.text)
menubar = self.menuBar()
exitAction = QtGui.QAction(QtGui.QIcon('exit.png'),'&Exit',self)
exitAction.setShortcut('Ctrl+Q')
exitAction.triggered.connect(self.close)
saveAction = QtGui.QAction(QtGui.QIcon('save.png'),'&Save',self)
saveAction.setShortcut('Ctrl+S')
saveAction.triggered.connect(self.save)
fileMenu = menubar.addMenu('&File')
fileMenu.addAction(exitAction)
fileMenu.addAction(saveAction)
self.show()
def save(self):
f = open(self.fileName.text(),'w')
f.write(self.text.toPlainText())
f.close()
def main():
app = QtGui.QApplication(sys.argv)
win = Window()
exit(app.exec_())
if __name__ == "__main__":
main()
謝謝!當我有機會的時候我會測試它。 – Awalrod