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
    244
    Thanks
    27
    Thanked 15 Times in 14 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
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    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. How to hide Close Button "X" on Widget ?
    By merry in forum Qt Programming
    Replies: 8
    Last Post: 25th January 2020, 09:03
  2. Replies: 2
    Last Post: 6th May 2011, 09:02
  3. How to Disabel close button on top corner of widget
    By jsmith in forum Qt Programming
    Replies: 4
    Last Post: 2nd August 2010, 17:57
  4. How to add close button to each tab widget Qtabwidget?
    By kishore7771 in forum Qt Programming
    Replies: 3
    Last Post: 4th April 2010, 09:42
  5. Close Button on Modal Widget?
    By vishal.chauhan in forum Qt Programming
    Replies: 5
    Last Post: 18th February 2008, 12: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.