Results 1 to 7 of 7

Thread: How to elide text in TextEdit

  1. #1
    Join Date
    Jan 2016
    Posts
    3
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default How to elide text in TextEdit

    hi All!
    There is Qml model and TableView in my application.
    TextEdit is used in delegate for text displaying (I use this element because I will use QSyntaxHighlighter with it)
    Also I use wrapMode: Text.NoWrap

    After column width changing I want get elide string (like ThisIsATex... for example)
    I use TextMetrics for text eliding (http://doc.qt.io/qt-5/qml-qtquick-te...tml#width-prop)

    Qt Code:
    1. onWidthChanged: {
    2. textMetrics.text = delegateTextEdit.text
    3. textMetrics.elideWidth = delegateTextEdit.width - 10
    4. var str = textMetrics.elidedText
    5. console.debug(str)
    6.  
    7. //delegateTextEdit.text = str
    8. }
    To copy to clipboard, switch view to plain text mode 

    Problem:
    - on width changing I can see correct elide text in console (in TableView it doesn't appear)
    qml_log.png
    - after last line uncommented I see text only at first column in my table. Yes, text is elided but only in one way
    qml_log1.jpg

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to elide text in TextEdit

    You will need a property that holds the actual text and use that as the input for your elide calculation.
    You can probably use the elidedText as the input for the TextEdit though.

    Something like

    Qt Code:
    1. TextEdit {
    2. id: delegateTextEdit
    3.  
    4. property string fullText: model.text
    5. text: deletateTextEditMetrics.elidedText
    6.  
    7. TextMetrics {
    8. id: delegateTextEditMetrics
    9.  
    10. text: delegateTextEdit.fullText
    11. elideWidth: delegateTextEdit.width - 10
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    Qyrychen (4th February 2016)

  4. #3
    Join Date
    Jan 2016
    Posts
    3
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to elide text in TextEdit

    Did the declarative approach not work?

    Cheers,
    _

  6. #5
    Join Date
    Oct 2014
    Posts
    104
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to elide text in TextEdit

    Hi @anda_skoa i did what you suggested above however, i seems have a problem with android.
    I found out that the elideWidth (TextInput.width - 10) is not enough to elide the text, when I tried deducting 200 from the width, it works fine.
    Btw, the provided example works perfectly in iOS.

    posted here is the sample code.

    Any advise? Thanks.

  7. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to elide text in TextEdit

    Maybe 10 is not enough offset, e.g. there could be margin or padding that is platform style specific, etc.

    Cheers,
    _

  8. #7
    Join Date
    Oct 2014
    Posts
    104
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to elide text in TextEdit

    Quote Originally Posted by anda_skoa View Post
    Maybe 10 is not enough offset, e.g. there could be margin or padding that is platform style specific, etc.

    Cheers,
    _
    Thanks for the reply.

    I was able to resolved the issue by explicitly setting the font.pointSize in Android.

Similar Threads

  1. QPushButton elide text
    By Cupidvogel in forum Qt Programming
    Replies: 4
    Last Post: 24th May 2015, 00:32
  2. Elide text
    By brcontainer in forum Qt Programming
    Replies: 3
    Last Post: 19th June 2013, 21:40
  3. How to set Text Elide Mode for QComboBox
    By kalos80 in forum Qt Programming
    Replies: 1
    Last Post: 27th February 2011, 09:42
  4. QListView Text Elide Like QListWidget
    By Kel Solaar in forum Qt Programming
    Replies: 6
    Last Post: 13th May 2010, 06:44
  5. visible text of textedit
    By regix in forum Qt Programming
    Replies: 3
    Last Post: 26th June 2006, 10:02

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.