Results 1 to 6 of 6

Thread: QTreeView Alignment

  1. #1
    Join Date
    Jun 2008
    Location
    Rome, Italy
    Posts
    95
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    19
    Thanked 2 Times in 2 Posts

    Default QTreeView Alignment

    Hi to all,
    I'm looking for a solution on alignment in a QTreeView. The default alignment is AlignLeft but I need to change it for a column. Does anybody know how to do?

    Thanks.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: QTreeView Alignment

    For the whole view you would simply override QAbstractItemView::viewOptions() but for a certain column you might have to implement a custom delegate, override QAbstractItemDelegate::paint() and adjust QStyleOptionViewItem::displayAlignment when the index points to appropriate column.
    J-P Nurmi

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QTreeView Alignment

    Or you can do it on the model level - simply set appropriate values for Qt::TextAlignmentRole.

  4. #4
    Join Date
    Jun 2008
    Location
    Rome, Italy
    Posts
    95
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    19
    Thanked 2 Times in 2 Posts

    Default

    Thanks jpn, I've read the documentation about your hint, it's the right way!
    Can you show me an example? if it's not so much trouble...

    Quote Originally Posted by wysota View Post
    Or you can do it on the model level - simply set appropriate values for Qt::TextAlignmentRole.
    Sorry wysota, where do i have to set the Qt::TextAlignmentRole in a QSqlTableModel?
    thanks
    Last edited by wysota; 15th June 2008 at 16:36.

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: QTreeView Alignment

    Quote Originally Posted by wysota View Post
    Or you can do it on the model level - simply set appropriate values for Qt::TextAlignmentRole.
    Indeed, I forgot there was such role.

    Quote Originally Posted by cydside View Post
    Sorry wysota, where do i have to set the Qt::TextAlignmentRole in a QSqlTableModel?
    thanks
    Subclass QSqlTableModel and reimplement data() to return desired alignment for Qt::TextAlignmentRole, otherwise call base class implementation.
    J-P Nurmi

  6. #6
    Join Date
    Jun 2008
    Location
    Rome, Italy
    Posts
    95
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    19
    Thanked 2 Times in 2 Posts

    Default Re: QTreeView Alignment

    Thanks jpn and wysota your hints are very precious!

Similar Threads

  1. QTreeView repaint
    By graeme in forum Qt Programming
    Replies: 17
    Last Post: 13th March 2012, 14:27
  2. QDirModel and QTreeView cut and paste
    By Micawber in forum Qt Programming
    Replies: 4
    Last Post: 28th May 2008, 21:16
  3. QTreeView help
    By bepaald in forum Qt Programming
    Replies: 1
    Last Post: 15th August 2007, 22:22
  4. QTreeView: Holding a line on screen
    By gri in forum Qt Programming
    Replies: 1
    Last Post: 7th August 2007, 12:42
  5. background image in QTreeView
    By momesana in forum Qt Programming
    Replies: 2
    Last Post: 11th January 2007, 07:25

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
  •  
Qt is a trademark of The Qt Company.