PDA

View Full Version : QPushButton, Icon right of text [solved]



Mike
29th January 2008, 10:15
Hi,

this is not a question, but something I want to share. I was looking for a way to place an icon right of the button text. This is useful for navigating datasets (first, prev, next, last).

http://www.michael-krueger.org/cms/images/stories/buttonbar.png

The easy way to do it, is to use QWidget::setLayoutDirection. So for the three buttons on the right you just need to do:


...
pushButtonNext->setLayoutDirection(Qt::RightToLeft);
pushButtonLast->setLayoutDirection(Qt::RightToLeft);
pushButtonNextIssue->setLayoutDirection(Qt::RightToLeft);
...

Have fun!

ashukla
29th January 2008, 10:49
Yes! Qt has Layout facility and you can also set the Layout direction of Qt Application using with void setLayoutDirection ( Qt::LayoutDirection direction) http://doc.trolltech.com/4.3/qapplication.html#layoutDirection-prop

elcuco
30th January 2008, 15:09
Please change the text of "Next" to "Next..." and tell me what happens

Misusing the layout direction is a bad idea.

Mike
31st January 2008, 10:30
... well it may doesn't fit all purposes, but it does fit for me.
I didn't find any other solution or sample so far. So if you know the "right" way doing it, please share ...

Thanks.

elcuco
31st January 2008, 21:47
I am sorry, I don't know the exact answer. But for future reference:

What are you doing, will result in text been showed as "...Right", even tough the "..." are typed after the word. This is because the text direction is changed as well, and for english it should always be LeftToRight and not RightToLeft.

For more information about this, please read this wikipedia page:
http://en.wikipedia.org/wiki/Bi-directional_text

(which kinda licks balls, since I was expecting it to show some examples of BiDi rendering)

wysota
31st January 2008, 21:53
Please change the text of "Next" to "Next..." and tell me what happens

Misusing the layout direction is a bad idea.

You can always use "...Next" in such case.


... well it may doesn't fit all purposes, but it does fit for me.
I didn't find any other solution or sample so far. So if you know the "right" way doing it, please share ...

I think the right way would be to implement a custom widget or send a suggestion report to TT :)