Results 1 to 6 of 6

Thread: QButton color changing in Qt 4.8 on Raspberry

  1. #1
    Join Date
    Feb 2016
    Posts
    3
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Exclamation QButton color changing in Qt 4.8 on Raspberry

    Hi to everyone,
    I have an issue with changing the color of a QPushButton. I have to change the color, of a pushbutton to green in certain conditions.

    I got the code working on Qt 4.8.6 on a Debian machine, but the same code (listed below) doesn't behave at the same manner on a Raspberry Pi.

    QPalette PHighlighted = palette();
    PHighlighted.setColor(QPalette::Button, QColor(Qt::green));
    ui->Btn->setPalette(PHighlighted);

    In the first case all the button becomes green with a black text, but on the Raspberry only a small frame around the edges of the button changes to green (with small to none visible effect).

    Any ideas?
    Thanks in advance

    P.S. I use Qt 4.8.6 with QtCreator 3.2.1 if it is helpful.

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

    Default Re: QButton color changing in Qt 4.8 on Raspberry

    Could be that the style on the RPi is using a different color role or you need to setAutoFillBackground(true) on the button.

    Cheers,
    _

  3. #3
    Join Date
    Feb 2016
    Posts
    3
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QButton color changing in Qt 4.8 on Raspberry

    Thanks for the fast reply!

    I tried inserting the line

    ui->Btn->setAutoFillBackground(true);

    at the class initialization and before each palette change that I had to make, but with no result. I also tried with using the Role option with all Active, Inactive and Disabled.
    The state of things didn't change: when the palette change is requested, only the frame changes its color.

    I checked at this point if it could be a library issue and updated the existing ones. I do not get a library error message during execution, so I assumed that no graphic library is missing.

    Thanks again a lot!

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

    Default Re: QButton color changing in Qt 4.8 on Raspberry

    You could try starting with a different widget style, so check if the style does things differently.

    E.g.
    application -style windows

    Cheers,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    TommyB90 (26th August 2016)

  6. #5
    Join Date
    Feb 2016
    Posts
    3
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QButton color changing in Qt 4.8 on Raspberry

    I just tried your solution.

    It seems to be working as the button now turns green when I want.
    The problem with this is that the shape of all the widget is changed and doesn't have rounded angles anymore.
    Cattura1.PNG
    Cattura2.PNG
    I will keep this as a temporary solution as it is working, but will try also with other ways.

    Thanks for all the help!

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

    Default Re: QButton color changing in Qt 4.8 on Raspberry

    You could check which style is normally loaded and try a different style.

    You could also try setting a style sheet instead of the palette or using a proxy style to draw just the button differently.

    Cheers,
    _

Similar Threads

  1. Replies: 0
    Last Post: 3rd July 2013, 18:51
  2. Replies: 4
    Last Post: 8th September 2011, 08:22
  3. Changing color of only one tab
    By Tiansen in forum Qt Programming
    Replies: 1
    Last Post: 7th January 2011, 04:34
  4. changing color of QTable
    By aj2903 in forum Qt Programming
    Replies: 7
    Last Post: 30th October 2009, 12:52
  5. Change color of QButton does not work with GTK
    By Teuniz in forum Qt Programming
    Replies: 3
    Last Post: 19th March 2009, 09:12

Tags for this Thread

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.