Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Problem with style sheet fonts



  • I'm relatively new to qt but when i set a style sheet on a label within my stacked widget i set the font colour to black using hex codes, this has worked before but now for some unknown reason when i run my app all fonts unspecified or specified are outputting white and i have no idea why, everything has been set to black as seen in attached images.0_1568007686297_Screen Shot 2019-09-09 at 3.41.08 pm.png
    0_1568007576322_Screen Shot 2019-09-09 at 3.18.09 pm.png


  • Moderators

    Do you modify the widget's palette by any chance? Using both QSS and QPalette does not work on a QLabel.



  • @sierdzio no i havent i didnt quite understand how palletes worked yet


  • Moderators

    OK.

    Ah, look at console output: it says that some properties are not recognized. Most likely you have changed the stylesheet and Qt can't parse it now. The really annoying thing about QSS is that when parsing fails, Qt will apply some of the styles, print a warning and ignore the rest of styling info. It's a perfect silent bug, very hard to notice and to fix.

    If you are using some source control like git, try bisecting back until you find a working version, then look into changes which happened since then. Also, if you have any compilation or runtime warnings - make sure you fix them.

    If you have upgraded Qt recently - try rolling back to the previous version. QSS sometimes breaks.



  • Thanks for the heads up on that runtime error i didnt even notice it, i fixed the bug causing that issue however it didnt have any effect of the text colour




  • Moderators

    I have nothing to add, sorry, no further ideas. You need to try and find exactly which change caused the problem.


  • Moderators

    @will_craig maybe it's a hierarchical issue, try to specify the exact object via #followed by the objectName

    for example:

    QLabel#label_8{
    background:"#4CAF50";
    font: 40pt "Helvetica" "#000000";
    }
    


  • @j-hilk thanks illl give it a go may take a bit cause ill have to redo it for every object



  • @sierdzio i just added this highlighted line into the main.cpp file and the output changed all of the text colours that were not attached to one of the stacked widgets pages that had layouts applied. So the ones without layouts changed the pages with remained the same.0_1568086269202_Screen Shot 2019-09-09 at 10.05.16 pm.png


Log in to reply