Qt control style setting, QSS grammar introduction

I. Introduction

QT is a relatively popular cross-platform application framework, which provides a rich control library and powerful tools for creating various types of applications. Although the default styles provided by QT look good, if you want to customize the appearance of your application, you can use QT Style Sheets (QSS) to set the appearance and behavior of controls.

QSS is a style sheet language based on CSS, which can easily modify the color, font, size, alignment and other attributes of the control, so as to realize the customized UI interface.

The following will introduce how to use the QSS syntax and style sheet setting method to create a custom and beautiful QT application interface.

image-20230725153815875

Two, QSS style syntax

QSS (QT Style Sheets) is a style sheet language based on CSS (Cascading Style Sheets), which is used to set the appearance and behavior of controls in QT applications. QSS has a similar syntax and properties to CSS, but also has some QT-specific extensions.

The following is an introduction to the syntax of the QSS style:

[1] selector

A selector is used to match the controls that need to be styled.

QSS supports the following selectors:

  • Class selector: start with ".", followed by the class name, such as ".QWidget".
  • ID selector: start with "#", followed by the ID name, such as "#myButton".
  • Pseudo-state selector: used to match a specific state of the control, such as ":hover"ÿ

Guess you like

Origin blog.csdn.net/xiaolong1126626497/article/details/131920668