Reputation: 147
Using Python 2.7 and PyQt4. So I need a way to make a text of the QPushButton editable when click on it, like on QTextEdit.
Upvotes: 1
Views: 471
Reputation: 1345
There is no builtin way to edit a push button in the sense that you have a cursor and can type along.
Probably the easiest solution is to bring up a QInputDialog. If that feels to heavy, you could also place a floating QLineEdit over or next to the QPushButton. Close that on <Enter>
and set the typed text to the QPushButton.
If you really want an editable Button, you'll have to subclass QPushButton and implement the desired functionality yourself. To get started with this, you need to reimplement mousePressEvent()
for starting your editing mode. Reimplement keyPressEvent()
for handling key strokes. If you need to display a cursor, reimplement paintEvent()
. I have no particular resource at hand that describes what exactly you have to do, but the terms above should be sufficient to look it up yourself.
Upvotes: 1