PDA

View Full Version : Vertical QProgressBar Text Direction



Pyral
4th February 2013, 22:16
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.

Santosh Reddy
4th February 2013, 22:39
If you are looking for horizontal text on a vertical bar, then it is not possible, unless you do some custom painting.

Pyral
5th February 2013, 02:46
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

void ProgressBar::paintEvent(QPaintEvent* event){
this->QProgressBar::paintEvent(event);
this->setTextVisible(false);
QPainter p(this);
//create QPointF location and QString q_pts; removed for brevity
p.drawText(location, q_pts);
}
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?

Lykurg
5th February 2013, 06:45
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.

wysota
5th February 2013, 12:37
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.

martynets
22nd January 2016, 14:32
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:

QProgressBar* pb2=new QProgressBar;

pb2->setOrientation(Qt::Vertical);
pb2->setTextDirection(QProgressBar::BottomToTop);
pb2->setRange(0, 100);
pb2->setValue(20);

current_layout->insertWidget(current_index++,pb2);

The text on the resulting progress bar is stil oriented top-to-bottom...
11657
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...

d_stranz
22nd January 2016, 15:29
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.

martynets
22nd January 2016, 20:36
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.