15, Qt Style Sheets

Qt stylesheet HTML like the CSS cascading style sheets, can, the entire window, the entire application assign a style for a separate outer subassembly.

Style sheet features: 1, optimizing the appearance. 2, to achieve some action, such as a mouse on the picture, the picture switching.

Format: QWidget :: setStyleSheet ( " Style " ) :: setStyleSheet or QApplication ( " style " )

Style: control class {attribute: value}

    The QPushButton, QCheckBoxes, a QComboBox { // buttons, radio buttons, drop-down box 
        Color: Red; // foreground 
        background-Color: White; // background color 
        font: Bold; // bold font 
    }

Implemented in two ways: 1, using the attribute column styleSheet property right. 2, the code

Mode 1:

Mode 2: label green background, red word

    ui-> label-> setStyleSheet ( " the QLabel {Color: Red; background-Color: Green;} " );
     // this-> setStyleSheet ( "the QLabel {Color: Red;}"); // class are all Label use this property

Control of action:

// mouse is over the hover, the switching pictures 
ui-> label-> setStyleSheet ( " the QLabel {border-Image: URL (: / 1.jpg);} " 
                           " the QLabel: hover {border-Image: URL (: / 2. PNG);} " );

Guess you like

Origin www.cnblogs.com/xixixing/p/10945248.html