¿Cómo puedo tener todo el texto seleccionado de forma predeterminada en mi edición de línea?

I'd like to be able to have all text highlighted in my lineEdit. However, the default selectAll() doesn't seem to do so.

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_())

I want to select the text on the lineEdit in the default constructor; however, it doesn't. Any reason for this? What should I be doing instead to accomplish this?

preguntado el 24 de agosto de 12 a las 05:08

¿Estás tratando de volver a implementar placeholderText? -

@Avaris Yes! That was it, except it is setPlaceholderText(str) -

0 Respuestas

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.