Results 1 to 3 of 3

Thread: QTextEdit widget: Add close (x) button

  1. #1
    Join Date
    May 2018
    Posts
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Question QTextEdit widget: Add close (x) button

    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.

  2. #2
    Join Date
    Jul 2012
    Posts
    228
    Thanks
    19
    Thanked 14 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTextEdit widget: Add close (x) button

    Qt 5.2 introduced a clearButton property. Is this what you mean?

    https://doc.qt.io/qt-5/qlineedit.htm...onEnabled-prop

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,385
    Thanks
    246
    Thanked 687 Times in 677 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: QTextEdit widget: Add close (x) button

    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.

    Capture.jpg
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 2
    Last Post: 6th May 2011, 08:02
  2. How to Disabel close button on top corner of widget
    By jsmith in forum Qt Programming
    Replies: 4
    Last Post: 2nd August 2010, 16:57
  3. How to hide Close Button "X" on Widget ?
    By merry in forum Qt Programming
    Replies: 7
    Last Post: 3rd May 2010, 18:04
  4. How to add close button to each tab widget Qtabwidget?
    By kishore7771 in forum Qt Programming
    Replies: 3
    Last Post: 4th April 2010, 08:42
  5. Close Button on Modal Widget?
    By vishal.chauhan in forum Qt Programming
    Replies: 5
    Last Post: 18th February 2008, 11:38

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.