Results 1 to 2 of 2

Thread: How to right-justify text line inside a QTreeView

  1. #1
    Join Date
    Apr 2014
    Posts
    125
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Android Maemo/MeeGo

    Question How to right-justify text line inside a QTreeView

    I have a QTreeView with cells (on the same column) each having very long texts. I want to display only the most right characters of the text since each text represents a very long file name.

    How to right justify the texts of the column of a QTreeView?

  2. #2
    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: How to right-justify text line inside a QTreeView

    If you are using QTreeView, then you are using a QAbstractItemModel (or a class derived from it), right?

    Implement the Qt::TextAlignmentRole for the QAbstractItemModel::data() method, and have it return Qt::AlignRight | Qt::AlignVCenter.

    Alternatively, if elided text is OK for you, then you could call QAbstractItemView::setTextElideMode() with the value Qt::ElideLeft. That will give you something that looks like "... very long file name" (but not the ability to scroll the text to the beginning).
    Last edited by d_stranz; 24th September 2014 at 03:39.

Similar Threads

  1. Writing single line inside a text file
    By Momergil in forum Qt Programming
    Replies: 3
    Last Post: 16th July 2013, 02:22
  2. Table inside QTreeView?
    By Bobruisk in forum Qt Programming
    Replies: 0
    Last Post: 11th July 2013, 11:05
  3. Reading a text line per line
    By Momergil in forum Newbie
    Replies: 0
    Last Post: 19th July 2011, 15:46
  4. Retrieving command line arguments inside a Qt application
    By prykHetQuo in forum Qt Programming
    Replies: 5
    Last Post: 14th February 2009, 14:28
  5. How to right-justify QLabel text
    By JimDaniel in forum Qt Programming
    Replies: 2
    Last Post: 30th January 2008, 08:55

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.