Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 731341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:00:56+00:00 2026-05-14T07:00:56+00:00

I am struggling to set an background image for an QPushButton. No Success till

  • 0

I am struggling to set an background image for an QPushButton. No Success till now. Following is my code.

appsWidget::appsWidget(QWidget *parent)
    :QWidget(parent)
{
    QPushButton *button1 = new QPushButton("SETTINGS",this);
    QPushButton *button2 = new QPushButton("TEST",this);
    QPushButton *button3 = new QPushButton("IE",this);

    button1->setStyleSheet("background-image:url(config.png)"); -> No success


    qDebug("appWidget initialized.");

    QHBoxLayout *layout = new QHBoxLayout;
    layout->addWidget(button1);
    layout->addWidget(button2);
    layout->addWidget(button3);
    this->setLayout(layout);
    connect(button1,SIGNAL(clicked()),this,SLOT(setClickIndex1()));
    connect(button2,SIGNAL(clicked()),this,SLOT(setClickIndex2()));
    connect(button3,SIGNAL(clicked()),this,SLOT(setClickIndex3()));
}

The image I am using in the stylesheet is located in the same project folder.
Do anybody has any solution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T07:00:57+00:00Added an answer on May 14, 2026 at 7:00 am

    You have to set the flat attribute to true:

    button1->setFlat(true);

    You also have to set the autofillbackground –

    button1->setAutoFillBackground(true);

    You may want to look at QToolButton which doesn’t require it to be flat in order to render an image. I’m using them in an app I’m writing at the moment and they look very nice:

    m_showAddCommentButton = new QToolButton();
    m_showAddCommentButton->setAutoFillBackground(true);
    palette = m_showAddCommentButton->palette();
    palette.setColor(QPalette::Button,QColor(82,110,166));
    m_showAddCommentButton->setPalette(palette);
    m_showAddCommentButton->setIcon(QIcon(":/uiImages/addComment_50_50.jpg"));
    m_showAddCommentButton->setIconSize(QSize(40,40));
    m_showAddCommentButton->setToolTip("Comment");
    connect(m_showAddCommentButton, SIGNAL(clicked()),
            manager, SLOT(showAddComment()));
    hLayout->addWidget(m_showAddCommentButton,0);
    

    (My image is stored as a resource)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been struggling with this for a while now. given a set of
I'm struggling to under the behaviour of the following html and css code. I'm
Been struggling with this for a couple days now. Here's the set up -
Being new to silverlight I'm struggling to 'get going' with the following. Basically I
I am struggling to set up the code coverage. What must i do, how
I'm struggling with how I would set up a database for a situation where
I am struggling with getting Inno Setup to set the check box to true
I have been struggling to make a set of reports that gives the sum
I see there are several posts regarding Cannot set Property and I'm still struggling
I'm struggling with add_custom_command. Let me explain the problem in detail. I've these set

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.