PDA

View Full Version : [QPushButton] text below icon



Tomasz
2nd December 2010, 23:23
Hello!

Is there any simple way to put text below icon on button? I've tried, but text is always on right. I know that there is Qt::LayoutDirection, but there is only from right to left or from left to right.

thanks in advance
best regards
Tomasz

wysota
2nd December 2010, 23:43
Use QToolButton instead of QPushButton and take a look at the properties it offers.

Tomasz
3rd December 2010, 10:29
Can I use only Qt::ToolButtonStyle? I'm asking because Qt::ToolButtonTextUnderIcon sets icon on top of the button (icon small and the button is big). Can I put it in the middle of a button?

thanks in advance
best regards
Tomasz

wysota
3rd December 2010, 11:55
Put what in the middle of the button?

Tomasz
3rd December 2010, 12:22
Icon. It's aligned to the top. I've tried to set it by stylesheet but with no result.

thanks in advance
best regards
Tomasz

wysota
3rd December 2010, 12:40
You can't put it in the middle because there is a text there... I don't think I understand your problem.

Tomasz
3rd December 2010, 13:07
You can't put it in the middle because there is a text there... I don't think I understand your problem.

Mayby I didn't put it clear. Sorry! So, I want text to be bottom-aligned and icon above it (in the middle of empty space of my button). Now I've got top-aligned icon, and text somewhere in the middle of empty space below icon.

thanks in advance
best regards
Tomasz

wysota
3rd December 2010, 13:09
Did you adjust the iconSize property to the size of your icon?

BalaQT
3rd December 2010, 13:24
hi, Tomasz,
u can resise ur icon , so tat ur text will be on the base. if u hav a small icon , the text will be in centre. when u increase the icon's size ur text will be positioned in the bottom.

hope it helps
Bala

Tomasz
3rd December 2010, 13:43
My button size is 150x100. Icon size is 50x50, and I've also set iconSize to 50x50 (don't want bigger). Maybe it's a little bit weird to make button that size but i would like it this way.

thanks in advance
best regards
Tomasz

wysota
3rd December 2010, 15:06
In that case it might be quicker to reimplement the paint event for the button and draw it yourself. Optionally you can place the icon on a larger pixmap so that the icon seems to be larger to fool QToolButton's layouting scheme.