2

I can change the image or any other style of a QPushButton in the designer by changing the stylesheet, but any change in the style sheet changes all the other properties.

For instance, when I change the border image everything else is changed and it does not inherit the rest of the properties from the parent (or windows style).

How can I keep the windows style while changing only the image?

scopchanov
  • 7,966
  • 10
  • 40
  • 68
polo
  • 23
  • 5
  • You can show a picture of what you currently get and what you want to get. – eyllanesc Dec 07 '17 at 16:28
  • @eyllanesc thanks, scopchanov already answered that part. Now the question is how to add an image to a pushbutton form inside QT Designer without changing anything else. Do you have any idea? – polo Dec 08 '17 at 12:21

2 Answers2

0

Did you try set style to the single push button:

your_push_button_pointer->setStyleSheet(
    "QPushButton{background-image: url(:/images/call_up.bmp);}" 
    "QPushButton:hover{background-image: url(:/images/call_hov.bmp);}" 
    "QPushButton:pressed{background-image: url(:/images/call_down.bmp);}");
  • Yes I did, but on that one push button other properties also change, not only the image. – polo Dec 08 '17 at 09:01
0

From How can I set Styles to a QTabwidget without overwriting existing styles in QT ?:

A style sheet is all or nothing. so if u all apply style sheet, it might sort of reset the look for some widgets and to fix that, you must supply a full stylesheet.

The key parts are:

  • A style sheet is all or nothing.
  • you must supply a full stylesheet.

You can set an image for the QPushButton from the code or by using QtDesigner like this:

  1. Select the button
  2. In the properties window set the image and the size (properties icon and iconSize).
scopchanov
  • 7,966
  • 10
  • 40
  • 68
  • Thanks, Is there a way of adding image to the button without using stylesheet? Or can I find windows stylesheet for push button somewhere? – polo Dec 08 '17 at 09:00
  • Is there a way I can do this from inside QT Designer (MSVC)? When I change the QTsth.h form inside visual studio it does not apply the changes? – polo Dec 08 '17 at 11:43
  • @polo what is QTsth.h? – scopchanov Dec 08 '17 at 12:52
  • it is the header file that keeps the code of the QT GUI generated in the designer (which can also be viewed from inside the designer by going to Form -> ViewCode). Its real name in my project is ui_QtGuiApplication2.h – polo Dec 08 '17 at 13:03
  • 1
    Thanks @scopchanov, you are a life saver. ;) – polo Dec 08 '17 at 13:23