Results 1 to 8 of 8

Thread: Vertical QProgressBar Text Direction

  1. #1
    Join Date
    Feb 2013
    Posts
    3
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Vertical QProgressBar Text Direction

    I made a vertical QProgressBar, but the text inside changed orientation with it. That is, the numbers inside have been rotated 90 degrees clockwise. Is there a way to rotate the text back, so it's right-side-up? After looking at the documentation, I thought using setTextDirection(QProgressBar::BottomToTop) would rotate the text, but it doesn't seem to do anything.

  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: Vertical QProgressBar Text Direction

    If you are looking for horizontal text on a vertical bar, then it is not possible, unless you do some custom painting.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

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

    Pyral (5th February 2013)

  4. #3
    Join Date
    Feb 2013
    Posts
    3
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Vertical QProgressBar Text Direction

    Thanks! Just so I know though, what does setTextDirection do? All the descriptions I've read make it sound like it rotates the text, so I'm a bit confused.
    Edit: I've encountered a confusing problem when trying to override paintEvent in my subclass of QProgressBar. I've written
    Qt Code:
    1. void ProgressBar::paintEvent(QPaintEvent* event){
    2. this->QProgressBar::paintEvent(event);
    3. this->setTextVisible(false);
    4. QPainter p(this);
    5. //create QPointF location and QString q_pts; removed for brevity
    6. p.drawText(location, q_pts);
    7. }
    To copy to clipboard, switch view to plain text mode 
    I'm getting the warnings
    QWidget::repaint: Recursive repaint detected
    QPainter::begin: Widget painting can only begin as a result of a paintEvent.
    The code seems to work, so what are these warnings, and how do I fix them?
    Last edited by Pyral; 5th February 2013 at 03:24. Reason: updated contents, wanted to avoid double post

  5. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Vertical QProgressBar Text Direction

    The text direction is for left-to-right and right-to-left languages. As for your code: do not call setTextVisible inside your paint event. It is enough to call it once and not every time a paint event occurs. Furthermore you can simply create a QWidget and use QStylePainter (Or use QStyle directly) to customize the appearance of the progress bar.

  6. The following user says thank you to Lykurg for this useful post:

    Pyral (5th February 2013)

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

    Default Re: Vertical QProgressBar Text Direction

    Just consider the situation that sometimes you may need to draw the text twice with clipping -- when the value of the progress bar is such that the bar ends intersecting the text. Then you need to draw part of the text with inverted (or otherwise changed) colours, just like the default bar does.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #6
    Join Date
    Jan 2016
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Vertical QProgressBar Text Direction

    I'm faced with the problem described in the initial question: call setTextDirection(QProgressBar::BottomToTop) makes no visual difference on the progress bar. The code is:
    Qt Code:
    1.  
    2. pb2->setOrientation(Qt::Vertical);
    3. pb2->setTextDirection(QProgressBar::BottomToTop);
    4. pb2->setRange(0, 100);
    5. pb2->setValue(20);
    6.  
    7. current_layout->insertWidget(current_index++,pb2);
    To copy to clipboard, switch view to plain text mode 
    The text on the resulting progress bar is stil oriented top-to-bottom...
    progressbar.png
    Question is how to get the text oriented bottom-to-top?

    Thank you in advance!

    UPDATE:
    This issue is caused by GTK+ style. The documentation says that some styles do not draw the text. This style seems to ignore the text direction option. From what I was able to test:
    - Motif, CDE and Plastique styles draw the text correctly;
    - Windows and Cleanlooks do not draw the text at all;
    - GTK+ is buggy - draws the text but ignores the text direction option.

    Hope this is helpful...
    Last edited by martynets; 22nd January 2016 at 20:25.

  9. #7
    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: Vertical QProgressBar Text Direction

    So does this part of the QProgressBar::setTextDirection() documentation apply to you?

    Note that whether or not the text is drawn is dependent on the style. Currently CleanLooks and Plastique draw the text. Mac, Windows and WindowsXP style do not.

  10. #8
    Join Date
    Jan 2016
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Vertical QProgressBar Text Direction

    Hi, thanks. Right, the root cause is in the style. I've just updated my question. Problem is with GTK+ style which is the default for my environment. Actually I use Qt 4.8 which set of styles differs from the Qt 5 but it doesn't matter...
    Thank you. Regards.

Similar Threads

  1. QProgressBar with custom text
    By smoon in forum Qt Programming
    Replies: 2
    Last Post: 10th May 2012, 15:44
  2. QProgressbar text format
    By jothy in forum Qt Programming
    Replies: 3
    Last Post: 4th August 2010, 18:02
  3. Replies: 2
    Last Post: 30th December 2008, 21:35
  4. Vertical text in a QTextDocument
    By Angelo Moriconi in forum Qt Programming
    Replies: 6
    Last Post: 7th February 2008, 05:30
  5. Vertical Orientation of Text.
    By ashukla in forum Qt Programming
    Replies: 9
    Last Post: 28th January 2008, 12:40

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.