PDA

View Full Version : Align text and icon of QToolButton on center



bibhukalyana
22nd November 2014, 13:18
Hi everyone,

Is it possible to place icon and text on center ?

code:


setIcon(icon);
setText(text);
setToolButtonStyle(Qt::ToolButtonTextBesideIcon);


If possible please help me.
Thanks

Bibhu.

anda_skoa
22nd November 2014, 15:20
You mean on top of each other?

Cheers,
_

bibhukalyana
23rd November 2014, 06:08
Thanks for reply.
No, side by side but in the middle(center) like for only text or icon

anda_skoa
23rd November 2014, 12:55
I am afraid I don't understand.

The text is already centered on the other axis, no?
I.e. if you set the text beside the icon, its vertical center is the same as the icon's vertical center, right?

Maybe you can do a screenshot of what you get and indicate what you would like to get?

Cheers,
_

bibhukalyana
24th November 2014, 07:15
Ohhh. I am really sorry.
Center means both vertical and horizontal.
Now it is vertically in center but horizontally in left.(Qt::AlignHCente | Qt::AlignVCenter or Qt::AlignCenter )

Thanks.

anda_skoa
24th November 2014, 08:30
If you center both items (icon and text) in both axis, then they are on top of each other.
Which I asked you about already and you said you didn't want to have.

So I am afraid words won't get us any further, we seem to have a different interpretation of what the center of an area is.

Cheers,
_

bibhukalyana
24th November 2014, 10:35
I want to put the combination of icon and text in the center but they should be placed side by side.
I was trying:
If in a widget some buttons are vertically present then it will appear in the center(If button background is transperent).

anda_skoa
24th November 2014, 12:46
You can try doing the horizontal alignment using a stylesheet, but you probably have to implement a QStyle proxy and reimplement drawControl() for QStyle::CE_ToolButtonLabel
Or derive from QToolButton, overwrite paintEvent() and call the style for everything other than the label.

Cheers,
_