Results 1 to 6 of 6

Thread: QHeaderView's text rotation

  1. #1
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Question QHeaderView's text rotation

    Dear Sirs and Madams!

    I have subclassed QHeaderView, it has some QStringList as model. Now, I would like to rotate column names in QHeaderView. What do I have to do, I am a little bit lost...? I am attaching reference screenshot.

    Sincerely,
    Marko

    B0gSl.png
    Qt 5.3 Opensource & Creator 3.1.2

  2. #2
    Join Date
    Apr 2012
    Location
    India.
    Posts
    88
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QHeaderView's text rotation

    Read QMatrix class it can be helpful to you for your requirement...
    Here I have given some code hint for you....

    QMatrix matrix;
    matrix.rotate(angle);
    pPainter->setWorldMatrix(matrix, true);

    Thanks,

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

    MarkoSan (21st August 2014)

  4. #3
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QHeaderView's text rotation

    Quote Originally Posted by Rajesh.Rathod View Post
    Read QMatrix class it can be helpful to you for your requirement...
    Here I have given some code hint for you....

    QMatrix matrix;
    matrix.rotate(angle);
    pPainter->setWorldMatrix(matrix, true);

    Thanks,
    I suppose this code belongs in reimplemented paintSection, am I right maybe?
    Qt 5.3 Opensource & Creator 3.1.2

  5. #4
    Join Date
    Apr 2012
    Location
    India.
    Posts
    88
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QHeaderView's text rotation

    Yes , you are right.

  6. #5
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Question Re: QHeaderView's text rotation

    I did that now:
    Qt Code:
    1. void HeaderViewHorizontal::paintSection(QPainter* painter,
    2. const QRect& rect,
    3. int logicalIndex) const
    4. {
    5. QMatrix matrix;
    6.  
    7. painter->save();
    8. matrix.rotate(45);
    9. painter->setWorldMatrix(matrix);
    10. painter->restore();
    11. }
    To copy to clipboard, switch view to plain text mode 
    but now the header's texts are not shown at all.


    Added after 7 minutes:


    I've forgotten to call drawText(), here is upgrade:
    Qt Code:
    1. void HeaderHorizontal::paintSection(QPainter* painter,
    2. const QRect& rect,
    3. int logicalIndex) const
    4. {
    5. QMatrix matrix;
    6.  
    7. // painter->save();
    8. matrix.rotate(45);
    9. painter->setWorldMatrix(matrix);
    10. painter->drawText(this->rect(),
    11. this->model()->headerData(logicalIndex,
    12. Qt::Horizontal).toString());
    13. // painter->restore();
    14. }
    To copy to clipboard, switch view to plain text mode 
    but now I get all titles at first section. Screenshot attached.horizHeaderTextAtFirstSection.jpg
    Last edited by MarkoSan; 21st August 2014 at 10:52.
    Qt 5.3 Opensource & Creator 3.1.2

  7. #6
    Join Date
    Apr 2012
    Location
    India.
    Posts
    88
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QHeaderView's text rotation

    You need to create new rectangle and need to move it's centre before calling draw text...

    int angle = 90;
    QMatrix matrix;
    matrix.rotate(angle);
    painter->setWorldMatrix(matrix);

    QRect new_r(0, 0, rect.height(), rect.width());
    switch(angle)
    {
    case 90:
    new_r.moveCenter(QPoint(rect.center().y(), -rect.center().x()-2));
    break;

    case -90:
    default:
    new_r.moveCenter(QPoint(-rect.center().y(), rect.center().x()));
    break;
    }

    rect = new_r;

    pHeaderView->style()->drawItemText(pPainter, new_r, Qt::AlignLeft,
    uniopt.palette, true, uniopt.text);

    For more code hint you can refer the code example given in link...
    http://qt-apps.org/content/show.php/...content=103154

    and you should implement this code in paintVeritcalSection function of given example

  8. The following user says thank you to Rajesh.Rathod for this useful post:

    MarkoSan (21st August 2014)

Similar Threads

  1. Rotation of Svgitems
    By alperyazir in forum Qwt
    Replies: 1
    Last Post: 21st May 2014, 06:45
  2. Replies: 0
    Last Post: 14th January 2014, 19:44
  3. Text rotation in QPainter
    By acpRobert in forum Newbie
    Replies: 1
    Last Post: 29th April 2009, 21:07
  4. Rotation on Qframe
    By Pharell in forum Qt Programming
    Replies: 11
    Last Post: 2nd April 2008, 16:31
  5. Rotation problem
    By boss_bhat in forum Qt Programming
    Replies: 5
    Last Post: 17th January 2007, 16:46

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.