Results 1 to 3 of 3

Thread: QHeaderView alignment

  1. #1
    Join Date
    Jan 2011
    Posts
    34
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QHeaderView alignment

    How to set different text alignment for each header's column, e.g. left for first column, right for second etc?

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QHeaderView alignment

    ...e.g. left for first column, right for second etc?
    You need to set flags in appropriate data role (Qt::TextAlignmentRole), also note if you have custom model then you need to support this feature.
    Qt Code:
    1. view->model()->setHeaderData(0, Qt::Horizontal, Qt::AlignLeft , Qt::TextAlignmentRole);
    2. view->model()->setHeaderData(1, Qt::Horizontal, Qt::AlignRight, Qt::TextAlignmentRole);
    To copy to clipboard, switch view to plain text mode 

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

    giantdragon (20th June 2011)

  4. #3
    Join Date
    Jan 2011
    Posts
    34
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QHeaderView alignment

    Thanks, now all works!

Similar Threads

  1. QHeaderView
    By waynew in forum Qt Programming
    Replies: 2
    Last Post: 25th December 2009, 20:42
  2. QHeaderView and its size
    By area51 in forum Qt Programming
    Replies: 1
    Last Post: 9th October 2009, 08:26
  3. QHeaderView
    By gyre in forum Qt Tools
    Replies: 1
    Last Post: 25th September 2007, 16:35
  4. QHeaderView as a banner
    By mclark in forum Qt Programming
    Replies: 1
    Last Post: 21st March 2007, 19:28
  5. QMenu in QHeaderView
    By munna in forum Qt Programming
    Replies: 9
    Last Post: 15th July 2006, 14:58

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.