QTabWidget
是 Qt 框架中用于创建选项卡式界面的控件。可以通过样式表(QSS
,Qt Style Sheets)来设置 QTabWidget
的外观。以下是一些常见的样式设置示例:
tab_widget.setStyleSheet("""
QTabWidget::pane {
border: 1px solid #ccc;
background-color: #f0f0f0;
}
QTabBar::tab {
background: #ddd;
border: 1px solid #ccc;
padding: 10px;
font-size: 14px;
}
QTabBar::tab:selected {
background: #f0f0f0;
border-bottom-color: #f0f0f0;
}
QTabBar::tab:hover {
background: #eee;
}
""")
tab_widget.setStyleSheet("""
QTabBar::tab {
width: 100px;
height: 30px;
}
""")
tab_widget.setStyleSheet("""
QTabBar::tab {
border-top-left-radius: 5px;
border-top-right-radius: 5px;
}
""")
tab_widget.setStyleSheet("""
QTabBar::tab {
background: #555;
color: white;
}
QTabBar::tab:selected {
background: #777;
color: yellow;
}
""")
tab_widget.setStyleSheet("""
QTabBar::tab {
padding-left: 20px; /* 图标和文本之间的间距 */
text-align: left; /* 文本左对齐 */
}
""")
tab_widget.setStyleSheet("""
QTabBar::close-button {
image: url(close.png); /* 关闭按钮的图标 */
subcontrol-position: right; /* 关闭按钮的位置 */
}
QTabBar::close-button:hover {
background: #f00; /* 鼠标悬停时的背景颜色 */
}
""")
tab_widget.setStyleSheet("""
QTabWidget::pane {
border: 2px solid #ccc;
margin: 0px;
padding: 0px;
}
QTabBar::tab {
margin: 0px;
padding: 5px;
}
""")
tab_widget.setStyleSheet("""
QTabBar::tab {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #E1E1E1, stop: 0.4 #DDDDDD,
stop: 0.5 #D8D8D8, stop: 1.0 #D3D3D3);
}
QTabBar::tab:selected {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #fafafa, stop: 1 #f0f0f0);
}
""")
tab_widget.setStyleSheet("""
QTabBar::tab {
border: 1px solid #ccc;
border-bottom-color: #f0f0f0; /* 底部边框颜色 */
margin-right: 2px; /* 选项卡之间的间距 */
box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.1); /* 阴影效果 */
}
""")
tab_widget.setStyleSheet("""
QTabBar::tab {
font-family: Arial;
font-size: 12px;
font-weight: bold;
}
""")
tab_widget.setStyleSheet("""
QTabBar::tab {
icon-size: 24px; /* 图标大小 */
}
""")
tab_widget.setStyleSheet("""
QTabBar::tab:hover {
background: #eee;
color: #000;
}
""")
tab_widget.setStyleSheet("""
QTabBar::tab:disabled {
background: #ccc;
color: #888;
}
""")
tab_widget.setStyleSheet("""
QTabBar::tab:selected {
background: #f0f0f0;
border-bottom-color: #f0f0f0;
}
""")
tab_widget.setStyleSheet("""
QTabBar::tab {
border-bottom: 2px solid #ccc;
}
QTabBar::tab:selected {
border-bottom: 2px solid #f00;
}
""")
tab_widget.setStyleSheet("""
QTabBar::tab {
border-top: 2px solid #ccc;
}
QTabBar::tab:selected {
border-top: 2px solid #f00;
}
""")
tab_widget.setStyleSheet("""
QTabBar::tab {
border-left: 2px solid #ccc;
border-right: 2px solid #ccc;
}
QTabBar::tab:selected {
border-left: 2px solid #f00;
border-right: 2px solid #f00;
}
""")
tab_widget.setStyleSheet("""
QTabBar::tab {
background-image: url(tab_bg.png);
}
QTabBar::tab:selected {
background-image: url(tab_bg_selected.png);
}
""")
tab_widget.setStyleSheet("""
QTabBar::tab {
border: 1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #ccc, stop: 1 #999);
}
QTabBar::tab:selected {
border: 1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #f00, stop: 1 #c00);
}
""")
tab_widget.setStyleSheet("""
QTabBar::tab {
border: 1px solid #ccc;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
}
QTabBar::tab:selected {
border: 1px solid #f00;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
}
""")
tab_widget.setStyleSheet("""
QTabBar::tab {
border: 1px solid #ccc;
box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.1);
}
QTabBar::tab:selected {
border: 1px solid #f00;
box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.1);
}
""")
tab_widget.setStyleSheet("""
QTabBar::tab {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #E1E1E1, stop: 0.4 #DDDDDD,
stop: 0.5 #D8D8D8, stop: 1.0 #D3D3D3);
border: 1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #ccc, stop: 1 #999);
}
QTabBar::tab:selected {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #fafafa, stop: 1 #f0f0f0);
border: 1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #f00, stop: 1 #c00);
}
""")
tab_widget.setStyleSheet("""
QTabBar::tab {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #E1E1E1, stop: 0.4 #DDDDDD,
stop: 0.5 #D8D8D8, stop: 1.0 #D3D3D3);
border: 1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #ccc, stop: 1 #999);
border-top-left-radius: 5px;
border-top-right-radius: 5px;
}
QTabBar::tab:selected {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #fafafa, stop: 1 #f0f0f0);
border: 1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #f00, stop: 1 #c00);
border-top-left-radius: 5px;
border-top-right-radius: 5px;
}
""")
tab_widget.setStyleSheet("""
QTabBar::tab {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #E1E1E1, stop: 0.4 #DDDDDD,
stop: 0.5 #D8D8D8, stop: 1.0 #D3D3D3);
border: 1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #ccc, stop: 1 #999);
box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.1);
}
QTabBar::tab:selected {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #fafafa, stop: 1 #f0f0f0);
border: 1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #f00, stop: 1 #c00);
box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.1);
}
""")
tab_widget.setStyleSheet("""
QTabBar::tab {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #E1E1E1, stop: 0.4 #DDDDDD,
stop: 0.5 #D8D8D8, stop: 1.0 #D3D3D3);
border: 1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #ccc, stop: 1 #999);
border-top-left-radius: 5px;
border-top-right-radius: 5px;
box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.1);
}
QTabBar::tab:selected {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #fafafa, stop: 1 #f0f0f0);
border: 1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #f00, stop: 1 #c00);
border-top-left-radius: 5px;
border-top-right-radius: 5px;
box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.1);
}
""")
tab_widget.setStyleSheet("""
QTabBar::tab {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #E1E1E1, stop: 0.4 #DDDDDD,
stop: 0.5 #D8D8D8, stop: 1.0 #D3D3D3);
border: 1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #ccc, stop: 1 #999);
border-top-left-radius: 5px;
border-top-right-radius: 5px;
box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.1);
}
QTabBar::tab:selected {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #fafafa, stop: 1 #f0f0f0);
border: 1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #f00, stop: 1 #c00);
border-top-left-radius: 5px;
border-top-right-radius: 5px;
box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.1);
}
""")
tab_widget.setStyleSheet("""
QTabBar::tab {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #E1E1E1, stop: 0.4 #DDDDDD,
stop: 0.5 #D8D8D8, stop: 1.0 #D3D3D3);
border: 1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #ccc, stop: 1 #999);
border-top-left-radius: 5px;
border-top-right-radius: 5px;
box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.1);
}
QTabBar::tab:selected {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #fafafa, stop: 1 #f0f0f0);
border: 1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #f00, stop: 1 #c00);
border-top-left-radius: 5px;
border-top-right-radius: 5px;
box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.1);
}
""")
tab_widget.setStyleSheet("""
QTabBar::tab {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #E1E1E1, stop: 0.4 #DDDDDD,
stop: 0.5 #D8D8D8, stop: 1.0 #D3D3D3);
border: 1px solid qlineargradient(x1