Qt控件样式设置

一、简述

QSS:全称 Qt Style Sheets(Qt样式表),用于美化Qt程序界面,类似于CSS,但不如CSS强大,选择器和属性较少。Qt定制化CSS。

QSS可以通过控件对象的setStyleSheet方法设置控件样式。

二、控件样式设置

2.1边框线

2.1.1按钮QPushButton

   //线粗细:1px
   //线类型:solid实线
   border:1px solid;

2.2背景色/字体颜色

2.2.1表格表行头/列头颜色

行头颜色(行列交叉也设置背景颜色):

   QHeaderView::section::horizontal,QTableCornerButton:section{ padding:3px; margin:0px; color:#DCDCDC;  border:1px solid #242424; border-left-width:0px; border-right-width:1px; border-top-width:0px; border-bottom-width:1px; background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #646464,stop:1 #525252); } QTableWidget{background-color:white;border:none;}
   QTableWidget::item:hover{background-color:rgb(92,188,227,200)}
   QTableWidget::item:selected{background-color:#1B89A1}

列头颜色:

   QHeaderView::section::vertical,QTableCornerButton:section{ padding:3px; margin:0px; color:#DCDCDC;  border:1px solid #242424; border-left-width:0px; border-right-width:1px; border-top-width:0px; border-bottom-width:1px; background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #646464,stop:1 #525252); } QTableWidget{background-color:white;border:none;}
   QTableWidget::item:hover{background-color:rgb(92,188,227,200)}
   QTableWidget::item:selected{background-color:#1B89A1}

2.3控件圆角弧度

   //角弧度,半径5的圆
  
   border-radius:5px;

2.4鼠标悬停颜色

   QHeaderView::section::horizontal,QTableCornerButton:section{ padding:3px; margin:0px; color:#DCDCDC;  border:1px solid #242424; border-left-width:0px; border-right-width:1px; border-top-width:0px; border-bottom-width:1px; background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #646464,stop:1 #525252); } QTableWidget{background-color:white;border:none;}
   QTableWidget::item:hover{background-color:rgb(92,188,227,200)}
	QTableWidget::item:selected{background-color:#1B89A1}

三、示例

   /*
   tabelwidget*/
   QTableWidget{
   color:#DCDCDC;
   background:#444444;
   border:1px solid #242424;
   alternate-background-color:#525252;/*交错颜色*/
   gridline-color:#242424;
   }
  
  /*选中item*/
  QTableWidget::item:selected{
  color:#DCDCDC;
  background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #484848,stop:1 #383838);
  }
  
  /*
  悬浮item*/
  QTableWidget::item:hover{
  background:#5B5B5B;
  }
 /*表头*/
  QHeaderView::section{
  text-align:center;
  background:#5E5E5E;
  padding:3px;
  margin:0px;
  color:#DCDCDC;
  border:1px solid #242424;
  border-left-width:0;
  }
  
  
  
  /*表右侧的滑条*/
  QScrollBar:vertical{
  background:#484848;
  padding:0px;
  border-radius:6px;
  max-width:12px;
  }
  
  /*滑块*/
  QScrollBar::handle:vertical{
  background:#CCCCCC;
  }
  /*
  滑块悬浮,按下*/
  QScrollBar::handle:hover:vertical,QScrollBar::handle:pressed:vertical{
  background:#A7A7A7;
  }
  /*
  滑块已经划过的区域*/
  QScrollBar::sub-page:vertical{
  background:444444;
  }
  
  /*
  滑块还没有划过的区域*/
  QScrollBar::add-page:vertical{
  background:5B5B5B;
  }
  
  /*页面下移的按钮*/
  QScrollBar::add-line:vertical{
  background:none;
  }
  /*页面上移的按钮*/
  QScrollBar::sub-line:vertical{
  background:none;
  }
  

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值