PDA

View Full Version : QTextEdit widget: Add close (x) button



ElenaV
21st May 2018, 14:12
Hello,

I am quite new in this area..
My main issue is how to add a close button (x) in the right up corner of the text editor in the same way as this button exists to a dialog etc. I need this button in order to close the text file which is currently displayed in the text editor or just "remove" the content of the text editor.

Thank you in advance.

tuli
25th May 2018, 16:51
Qt 5.2 introduced a clearButton property. Is this what you mean?

https://doc.qt.io/qt-5/qlineedit.html#clearButtonEnabled-prop

d_stranz
26th May 2018, 17:35
The question concerns QTextEdit, not QLineEdit.

I would solve this problem by embedding the QTextEdit into a QWidget parent. Put a QVBoxLayout into the QWidget, then add a QHBoxLayout inside that. Add a QToolButton to the horizontal layout, and use a Horizontal spacer to push it to the right. Add your QTextEdit under the QHBoxLayout as the second item in the QVBoxLaout. See the screenshot below.

12833