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 7555649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:39:45+00:00 2026-05-30T11:39:45+00:00

I would like to set a QToolButton’s icons using style sheets, like this :

  • 0

I would like to set a QToolButton’s icons using style sheets, like this :

#include <QToolButton>
#include <QApplication>

QString FormStyleSheetString( const QString & name )
{
  const QString thisItemStyle( "QToolButton:enabled { image: url(" + name + "_normal.png); }  "
                             "QToolButton:pressed { image: url(" + name + "_pressed.png); }  "
                             "QToolButton:disabled { image: url(" + name + "_disabled.png); }  "
                           );

  return thisItemStyle;
}

int main(int argc, char * argv[])
{
    QApplication qapp(argc,argv);

    QToolButton button;
    button.setStyleSheet( FormStyleSheetString( "button" ) );
    button.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
    button.setIconSize(QSize(200,200));
    button.setText("some thing..." );
    button.show();

    return qapp.exec();
}

I compiled it like this :

g++ -O3 -std=c++0x -Wall -Wextra -pedantic test.cpp -lQtCore -lQtGui -I/usr/include/Qt/ -I/usr/include/QtCore/ -I/usr/include/QtGui/

Unfortunately, the above doesn’t work (the icon is not shown).

If I use setIcon, then the icon is shown properly.

So, what am I doing wrong? How to set the button’s icon using style sheet?

The images I used are :
button_normal.png
button_pressed.png
button_disabled.png

PS Take a note that I asked similar question here, but the answer doesn’t work once the text is set (the icon is all squished, and the text is not below the icon).

EDIT 1:
I also tried this function (as Kamil Klimek suggested) :

QString FormStyleSheetString( const QString & name )
{
  const QString thisItemStyle( "QToolButton { qproperty-icon: url(" + name + "_normal.png); };  "
                               "QToolButton:pressed { qproperty-icon: url(" + name + "_pressed.png); };  "
                               "QToolButton:hover { qproperty-icon: url(" + name + "_disabled.png); };  "
                               );

  return thisItemStyle;
}

but it also didn’t work. Pressing the button, or hovering, doesn’t change the icon.

  • 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-30T11:39:47+00:00Added an answer on May 30, 2026 at 11:39 am

    Later that day I managed to somehow solve the problem, but forgot to post the solution :

    QString FormStyleSheetString( const QString & name )
    {
      const QString thisItemStyle(
      "QToolButton {\n"
                    "   border: none;\n"
                    "   background: url(" + name + "_normal.png) top center no-repeat;\n"
                    "   padding-top: 200px;\n"
                    "   width: 200px;\n"
                    "   font: bold 14px;\n"
                    "   color: red;\n"
                    "}\n"
                    "QToolButton:hover {\n"
                    "   background: url("+name+"_hover.png) top center no-repeat;\n"
                    "   color: blue;\n"
                    "}\n"
                    "QToolButton:pressed {\n"
                    "   background: url("+name+"_pressed.png) top center no-repeat;\n"
                    "   color: gray;\n}" );
    
      return thisItemStyle;
    }
    

    It wasn’t enough just to set the background. It also needed the size fixed.

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

Sidebar

Related Questions

I would like to set up some WMV Video Streaming, using Windows 2003's Streaming
I would like to set values on an url like this: <a href='http://$data_url/viewyournote.php?chapter='$name_of_chapter'&note='$id_note'&user='$username'> Then
I would like to set a text field with watir-webdriver using css selectors to
I would like to set custom color programmatically using the method [UIColor colorWithRed:(CGFloat)red green:(CGFloat)green
I would like to set up an automatic backup of changed/saved text files using
I would like to set up the following custom notation in Mathematica 7. This
would like to set this convention up globally if possible.
I would like to set the MSMQ message label using the NetMsmqBinding. I understand
I would like set null in all fields in one user. If this is
I would like to set the log file name for a log4j and log4net

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.