Using variables in qt StyleSheets

前端 未结 4 1494
無奈伤痛
無奈伤痛 2021-01-04 03:31

Is there any possibility of giving variable name to hex/rgb numbers in .qss file . For eh

myColor = #FFCC08
QPushButton { background-color: myColor;}
         


        
4条回答
  •  心在旅途
    2021-01-04 03:49

    You could build your own tiny Sass quite easily:

    1.Create a text file with definitions of variables. Use simple format like this:

    @myColor  = #FFDDEE
    @myColor2 = #112233 
    @myWidth  = 20px
    

    2.In qss file use variable names:

    QPushButton { 
        background-color: @myColor; 
        min-width: @myWidth;
    }
    

    3.Open both files and for each variable in definition file change its occurrence in qss file with the value (string) from the definition file. It is a simple string replacement.

    4.Apply the preprocessed qss in the app.

    This is the simplest solution. You can change both definition file and qss file outside the app and apply it without recompilation of code.

提交回复
热议问题