Search code examples
qtstylesheetqstring

Qt stylesheet and QString::arg()


To keep a Stylesheet dynamic regarding DPI settings, I want to set certain parts of it from code.

This works:

my_label->setStyleSheet( QString( "font-size: 30px;" ) );

Yet, this doesn't:

my_label->setStyleSheet( QString( "font-size: %1px;" ).arg( 30 ) );

Can anyone enlighten me, why this is? Running Qt 5.7.


Solution

  • The issue was a combination of two things:

    1. I needed to convert the value to a string first
    2. The actual value passed to the arg() during runtime had a decimal place, the "30" was just for testing

    While I did try different combinations (integer values (30), converting to QString first), I did not try using an integer value AND converting it to QString together. So everyone was kinda right. Thanks for the patience.