qt设置控件的风格样式

设置tablewidget

ui.tableWidget_MaterialLibrary->setStyleSheet("QTableView {"
        "color:#DCDCDC;"
        "background-color: #444444;"
        "border: 1px solid #242424;"
        "alternate-background-color:#525252;"
        "gridline-color: #242424;"
        "}"
        "QHeaderView::section {"
        "background-color: #444444;"
        "font:13pt '黑体';"
        "color: rgb(57,233,235);"
        "}"
        "QScrollBar:horizontal {"
        "background-color: #f5f5f5;"
        "height: 10px;"
        "}"
        "QScrollBar::handle:horizontal {"
        "background-color: #ccc;"
        "border-radius: 5px;"
        "}"
        "QScrollBar::add-line:horizontal, QScrollBar::sub-line:horizontal {"
        "background-color: #f5f5f5;"
        "width: 10px;"
        "}"
        "QScrollBar::add-page:horizontal, QScrollBar::sub-page:horizontal {"
        "background-color: #f5f5f5;"
        "}");

设置表头样式

 ui.tableWidget_MaterialLibrary->horizontalHeader()->setStyleSheet("QHeaderView::section{background-color:#444444;font:13pt '黑体';color: rgb(57,233,235);}");

设置Lineedit样式

   QString sSheet = "QLineEdit {"
        "background-color: #444444;"//背景颜色
        "border: 1px solid #ccc;"//边框颜色
        "border-radius: 5px;"//边框弧度
        "padding: 2px;"
        "border-width:2px;"//边框大小
        "color:#DCDCDC;"//前景颜色 字体颜色
        "}";
    ui.lineEdit->setStyleSheet(sSheet);

设置GroupBox样式

 QString  sSheet = "QGroupBox {"
        "border: 1px solid #444444;"
        "border-radius: 5px;"
        "margin-top: 10px;"
        "}"
        "QGroupBox::title {"
        "subcontrol-origin: margin;"
        "subcontrol-position: top left;"
        "padding: 5px;"
        "background-color: #f5f5f5;"//透明白色
        "}"
        "QGroupBox::indicator {"
        "width: 15px;"
        "height: 15px;"
        "}"
        "QGroupBox::indicator:unchecked {"
        "border: 1px solid #ccc;"
        "border-radius: 7px;"
        "background-color: white;"
        "}"
        "QGroupBox::indicator:checked {"
        "border: 1px solid #0078d7;"//蓝色
        "border-radius: 7px;"
        "background-color: #00FF00;"//绿色
        "}";
    ui.groupBox->setStyleSheet(sSheet);

设置CheckBox的样式

sSheet = "QCheckBox {"
    "spacing: 5px;"
    "}"
    "QCheckBox::indicator {"
    "width: 15px;"
    "height: 15px;"
    "}"
    "QCheckBox::indicator:unchecked {"
    "border: 1px solid #ccc;"
    "background-color: white;"
    "}"
    "QCheckBox::indicator:checked {"
    "border: 1px solid #0078d7;"
    "background-color: #FF0000;"
    "}";
ui.checkBox->setStyleSheet(sSheet);

设置PushButton的样式

sSheet = "QPushButton {"
    "background-color: #444444;"
    "border: 1px solid #ccc;"
    "border-width:2px;"//边框大小
    "color: white;"
    "padding: 5px 16px;"
    "border-radius: 5px;"
    "}"
    "QPushButton:hover {"
    "background-color: #005ea3;"
    "}"
    "QPushButton:pressed {"
    "background-color: #00FFFF;"
    "}";
ui.pushButton_add->setStyleSheet(sSheet);

设置RadioButton的样式

  sSheet = "QRadioButton {"
        "spacing: 5px;"
        "}"
        "QRadioButton::indicator {"
        "width: 15px;"
        "height: 15px;"
        "}"
        "QRadioButton::indicator:unchecked {"
        "border: 1px solid #ccc;"
        "border-radius: 7px;"
        "background-color: white;"
        "}"
        "QRadioButton::indicator:checked {"
        "border: 1px solid #0078d7;"
        "border-radius: 7px;"
        "background-color: #0078d7;"
        "}";

    ui.radioButton_p80->setStyleSheet(sSheet);

设置ComboBox的样式

 sSheet = "QComboBox {"
        "background-color: #FF6347;"// 设置背景颜色
        "border: 1px solid #ccc;"// 设置背景颜色为白色
        "border-radius: 5px;"// 设置边框的圆角为5像素
        "padding: 2px;"// 设置内边距为2像素的上下边距和8像素的左右边距
        "}"
        "QComboBox::drop-down {"
        "subcontrol-origin: padding;"// 设置内边距为2像素的上下边距和8像素的左右边距
        "subcontrol-position: top right;"// 设置内边距为2像素的上下边距和8像素的左右边距
        "width: 15px;"// 设置下拉按钮的宽度为20像素
        "border-left-width: 1px;"
        "border-left-color: #ccc;"
        "border-top-right-radius: 5px;"// 设置下拉按钮的右上角圆角为5像素
        "border-bottom-right-radius: 5px;"// 设置下拉按钮的右下角圆角为5像素
        "background-color: #ADD8E6;" // 设置下拉按钮的背景颜色为浅灰色
        "}"
        "QComboBox::down-arrow {"
        "image: url(:/images/down_arrow.png);" // 
        "}";
    ui.comboBox->setStyleSheet(sSheet);

设置Label的样式

sSheet = "QLabel {"
    "color: #333;"
    "border:1px solid #ccc;"
    "}";
ui.label_2->setStyleSheet(sSheet);

你可能感兴趣的:(qt,开发语言,c++)