一、主界面
1、窗口 最小化 最大化 关闭按钮、显示状态自定义
2、隐藏任务栏显示
3、关闭按钮实现的功能
4、绘制背景图片并且实现圆角效果
5、设置应用程序的字体
6、设置组件字体
7、超链接
QLabel *url_label = new QLabel();
url_label->setOpenExternalLinks(true);//这句比较关键,也可以通过连接linkActivated信号到自定义槽函数中打开
url_label->setText(tr("Google"));
8、打开本地文件(夹)
QDesktopServices::openUrl(QUrl::fromLocalFile(local_file));
9、显示窗口并激活/提升
showNormal();
raise();
activateWindow();
10、设置滚动条值
textEdit->verticalScrollBar()->setValue(0); //
滚动到最顶层
textEdit->verticalScrollBar()->setValue(textEdit->verticalScrollBar()->maximum());// 滚动到最底层
二、全屏显示与还原
1、遮挡任务栏:
2、不遮挡任务栏:
}
三、QSS样式
1、QComboBox:
combo_box->setStyleSheet("QComboBox{border:1px solid gray;}"
2、QSpinBox:
spin_box->setStyleSheet("QSpinBox{border:1px solid gray;}"
3、QMenu:
padding:5px;
border:1px solid gray;
padding:0px 40px 0px 30px;
height:25px;
margin:5px 0px 5px 0px;
4、QSlider:
QSlider::groove:horizontal{
border:0px;
height:4px;
}
QSlider::sub-page:horizontal{
}
QSlider::add-page:horizontal{
}
QSlider::handle:horizontal{
background:white;
width:10px;
border-radius:5px;
margin:-3px 0px -3px 0px;
}
5、QCheckBox:
QCheckBox{
spacing: 2px;
}
QCheckBox::indicator {
width: 20px;
height: 20px;
}
QCheckBox::indicator:unchecked {
image: url(:/login/checkbox);
}
QCheckBox::indicator:unchecked:hover {
image: url(:/login/checkbox_hover);
}
QCheckBox::indicator:unchecked:pressed {
image: url(:/login/checkbox_press);
}
QCheckBox::indicator:checked {
image: url(:/login/checkbox_selected);
}
QCheckBox::indicator:checked:hover {
image: url(:/login/checkbox_selected_hover);
}
QCheckBox::indicator:checked:pressed {
image: url(:/login/checkbox_selected_press);
}
6、QScrollBar:
QScrollBar{
background:transparent;
}
QScrollBar::handle{
background:rgb(180, 180, 180, 150);
}
QScrollBar::handle:hover{
background:rgb(150, 150, 150, 180);
}
QScrollBar::add-page{
background:transparent;
}
QScrollBar::sub-page{
background:transparent;
}
QScrollBar::sub-line{
background:transparent;
}
QScrollBar::add-line{
background:transparent;
}
7、QStatusBar
QStatusBar::item{
border: 0px;
}
8、QComboBox
QComboBox {
border-image: url(:/OverdraftControl/comboBox);
}
QComboBox:hover {
border-image: url(:/OverdraftControl/comboBoxHover);
}
QComboBox:pressed {
border-image: url(:/OverdraftControl/comboBoxPressed);
}
QComboBox::down-arrow {
image: none;
}
QComboBox::drop-down {
width: 15px;
border: none;
}
QComboBoxQAbstractItemView {
border: 1px solid lightgray;
outline: 0px;//去掉item虚线
}
QComboBoxQAbstractItemView::item {
color: black;
height: 22px;
border: 1px solid transparent;
}
QComboBoxQAbstractItemView::item:selected {
border: 1px solid rgb(170, 190, 230);
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 rgb(230, 240, 250), stop: 0.5rgb(220, 235, 255), stop: 1.0 rgb(210, 230, 255));
}
一般也可以使用QPalette
QPalette palette;
palette.setBrush(QPalette::WindowText, QBrush(Qt::white));
check_box->setPalette(palette);
check_box->setStyleSheet("color:white");
调色板类QPalette提供了颜色角色(color roles)的概念,指当前界面中颜色的职责,通过枚举变量
QPalette::ColorRole来定义,比较常用的角色有:
QPalette::Window
QPalette::WindowText
QPalette::Base
QPalette::Text
QPalette::Button
QPalette::ButtonText
联系客服