1

我希望能够在我的 lineEdit 中突出显示所有文本。但是,默认的 selectAll() 似乎没有这样做。

import sys
from PyQt4 import QtCore, QtGui
from gui import Ui_Form

class MyForm(QtGui.QMainWindow):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_Form()
        self.ui.setupUi(self)
        self.ui.lineEdit.setText("Type something here!")
        self.ui.lineEdit.selectAll()
        QtCore.QObject.connect(self.ui.pushButton, QtCore.SIGNAL("clicked()"), self.ui.textEdit.clear)
        QtCore.QObject.connect(self.ui.lineEdit, QtCore.SIGNAL("returnPressed()"), self.add_entry)

    def add_entry(self):
        self.ui.lineEdit.selectAll()
        self.ui.lineEdit.cut()
        self.ui.textEdit.append("")
        self.ui.textEdit.paste()


if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    myapp = MyForm()
    myapp.show()
    sys.exit(app.exec_())

我想在默认构造函数中选择 lineEdit 上的文本;但是,事实并非如此。这有什么原因吗?我应该怎么做才能做到这一点?

4

0 回答 0