×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Regular Contributor
    Join Date
    Aug 2009
    Posts
    331

    How to place button text at center on QPushButton image?

    Hi,

    I want to display text on a QPushButton with image at center. The image is displayed properly but the text is displayed left aligned or right aligned, hoe to place it on center of the QPushButtton Image.

    Any suggestions!

    Thanks.

  2. #2
    Registered User
    Join Date
    Jul 2004
    Posts
    166

    Re: How to place button text at center on QPushButton image?

    Can you paste your code, some one might able to help.
    http://kunalmaemo.blogspot.com/

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    18

    Re: How to place button text at center on QPushButton image?

    Hi,

    You can place the text at the center of the QPushButton Image using setStyleSheet() method.
    Please try the following code snippet:

    QPushButton *m_button = new QPushButton("My Button", this);
    m_button->setStyleSheet("background-image: url(:/PngTest.png);"
    "background-repeat: no-repeat;"
    "background-position: center center");


    The above snippet will set the text at the center on the QPushButton Image.
    Hope this information solves your issue.

    --Mayura.

Similar Threads

  1. Text wrapping in QPushButton
    By junifiedx in forum [Archived] Beginning Qt
    Replies: 5
    Last Post: 2011-06-18, 17:57
  2. QPushButton Text
    By maruthisri in forum Qt
    Replies: 4
    Last Post: 2010-06-09, 11:53
  3. Replies: 2
    Last Post: 2010-05-18, 15:21
  4. center button
    By reshmy in forum Mobile Java General
    Replies: 4
    Last Post: 2008-09-18, 18:32

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •