Results 1 to 8 of 8

Thread: Align text and icon of QToolButton on center

  1. #1
    Join Date
    Mar 2011
    Posts
    120
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Align text and icon of QToolButton on center

    Hi everyone,

    Is it possible to place icon and text on center ?

    code:
    Qt Code:
    1. setIcon(icon);
    2. setText(text);
    3. setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
    To copy to clipboard, switch view to plain text mode 

    If possible please help me.
    Thanks

    Bibhu.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Align text and icon of QToolButton on center

    You mean on top of each other?

    Cheers,
    _

  3. #3
    Join Date
    Mar 2011
    Posts
    120
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Align text and icon of QToolButton on center

    Thanks for reply.
    No, side by side but in the middle(center) like for only text or icon

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Align text and icon of QToolButton on center

    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,
    _

  5. #5
    Join Date
    Mar 2011
    Posts
    120
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Align text and icon of QToolButton on center

    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.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Align text and icon of QToolButton on center

    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,
    _

  7. #7
    Join Date
    Mar 2011
    Posts
    120
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Align text and icon of QToolButton on center

    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).

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Align text and icon of QToolButton on center

    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,
    _

Similar Threads

  1. Qwt, Align content to center
    By Asting in forum Qwt
    Replies: 3
    Last Post: 18th June 2014, 11:06
  2. Creating a list with icon and text in the center of icon
    By prophet0 in forum Qt Programming
    Replies: 2
    Last Post: 15th December 2011, 03:03
  3. Replies: 1
    Last Post: 4th April 2011, 19:41
  4. Replies: 0
    Last Post: 23rd March 2011, 05:07
  5. How to align list items to the center?
    By zgulser in forum Qt Tools
    Replies: 4
    Last Post: 9th February 2009, 09:52

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.