QMessageBox样式

This commit is contained in:
Irony 2018-01-17 22:47:55 +08:00
parent 9da1b749f5
commit 1e5eb85b7e
40 changed files with 507 additions and 2 deletions

View file

@ -19,6 +19,14 @@ encoding//\u5B57\u4F53\u6D4B\u8BD5/TestFontRoboto.py=utf-8
encoding//\u68A6\u5E7B\u6811/DreamTree.py=utf-8
encoding//\u6D4F\u89C8\u5668\u83B7\u53D6Cookie/WebEngineView.py=utf-8
encoding//\u6D4F\u89C8\u5668\u83B7\u53D6Cookie/WebView.py=utf-8
encoding//\u754C\u9762\u7F8E\u5316/QMessageBox\u6837\u5F0F/\u65B9\u6848\u4E00/critical.py=utf-8
encoding//\u754C\u9762\u7F8E\u5316/QMessageBox\u6837\u5F0F/\u65B9\u6848\u4E00/information.py=utf-8
encoding//\u754C\u9762\u7F8E\u5316/QMessageBox\u6837\u5F0F/\u65B9\u6848\u4E00/question.py=utf-8
encoding//\u754C\u9762\u7F8E\u5316/QMessageBox\u6837\u5F0F/\u65B9\u6848\u4E00/warning.py=utf-8
encoding//\u754C\u9762\u7F8E\u5316/QMessageBox\u6837\u5F0F/\u65B9\u6848\u4E8C/critical.py=utf-8
encoding//\u754C\u9762\u7F8E\u5316/QMessageBox\u6837\u5F0F/\u65B9\u6848\u4E8C/information.py=utf-8
encoding//\u754C\u9762\u7F8E\u5316/QMessageBox\u6837\u5F0F/\u65B9\u6848\u4E8C/question.py=utf-8
encoding//\u754C\u9762\u7F8E\u5316/QMessageBox\u6837\u5F0F/\u65B9\u6848\u4E8C/warning.py=utf-8
encoding//\u7A0B\u5E8F\u91CD\u542F/AutoRestart.py=utf-8
encoding//\u7A97\u53E3\u91CD\u542F/RestartMainWindow.py=utf-8
encoding//\u81EA\u52A8\u66F4\u65B0/mylibs/testlibs.py=utf-8

View file

@ -16,7 +16,7 @@
- [1.11 浏览器获取Cookie](浏览器获取Cookie/)
- [1.12 全局热键](全局热键/)
- [1.13 图片加载](图片加载/)
- [1.4 窗口重启](窗口重启/)
- [1.14 窗口重启](窗口重启/)
### [2.QGraphicsView练习](QGraphicsView练习/)
- [2.1 世界地图](QGraphicsView练习/世界地图)
@ -26,3 +26,6 @@
### [3.PyQtChart练习](PyQtChart练习/)
- [3.1 charts](PyQtChart练习/charts)
- [3.2 test](PyQtChart练习/test)
### [4.界面美化](界面美化/)
- [4.1 QMessageBox样式](界面美化/QMessageBox样式)

View file

@ -0,0 +1,11 @@
# 消息提示框的按钮和图标美化
### [1.方案一](方案一/)
- 1.1 该方案使用dialogbuttonbox-buttons-have-icons: 1; 开启自带的图标样式
- 1.2 再利用dialog-xx-icon: url(); 来设置自定义的图标, 具体参考[list-of-icons](http://doc.qt.io/qt-5/stylesheet-reference.html#list-of-icons)
- 1.3 缺点 部分按钮图标无效,无法自定义不同按钮的颜色
### [2.方案二](方案二/)
- 2.1 采用样式表中的属性选择器 QPushButton[text="xxx"] 可以根据按钮中的文字来区分
- 2.2 在利用属性样式qproperty-icon: url();来设置自定义图标
- 2.3 解决方案一的缺点

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

View file

@ -0,0 +1,7 @@
# 方案一
截图
![critical](ScreenShot/critical.png)
![information](ScreenShot/information.png)
![question](ScreenShot/question.png)
![warning](ScreenShot/warning.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

View file

@ -0,0 +1,40 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Created on 2018年1月17日
@author: Irony."[讽刺]
@site: http://alyl.vip, http://orzorz.vip, https://coding.net/u/892768447, https://github.com/892768447
@email: 892768447@qq.com
@file: critical
@description:
'''
__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com"
__Copyright__ = "Copyright (c) 2018 Irony.\"[讽刺]"
__Version__ = "Version 1.0"
import sys
from PyQt5.QtWidgets import QApplication, QMessageBox
app = QApplication(sys.argv)
app.setStyleSheet('''QDialogButtonBox {
dialogbuttonbox-buttons-have-icons: 1;
dialog-ok-icon: url(../icons/Ok.png);
dialog-open-icon: url(../icons/Open.png);
dialog-save-icon: url(../icons/Save.png);
dialog-cancel-icon: url(../icons/Cancel.png);
}
QMessageBox {
messagebox-critical-icon: url(../icons/Close.png);
}
''')
QMessageBox.critical(None, "提示critical", "消息",
QMessageBox.Ok |
QMessageBox.Open |
QMessageBox.Save |
QMessageBox.Cancel)
sys.exit()

View file

@ -0,0 +1,40 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Created on 2018年1月17日
@author: Irony."[讽刺]
@site: http://alyl.vip, http://orzorz.vip, https://coding.net/u/892768447, https://github.com/892768447
@email: 892768447@qq.com
@file: information
@description:
'''
__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com"
__Copyright__ = "Copyright (c) 2018 Irony.\"[讽刺]"
__Version__ = "Version 1.0"
import sys
from PyQt5.QtWidgets import QApplication, QMessageBox
app = QApplication(sys.argv)
app.setStyleSheet('''QDialogButtonBox {
dialogbuttonbox-buttons-have-icons: 1;
dialog-close-icon: url(../icons/Close.png);
dialog-discard-icon: url(../icons/Discard.png);
dialog-apply-icon: url(../icons/Apply.png);
dialog-reset-icon: url(../icons/Reset.png);
}
QMessageBox {
messagebox-information-icon: url(../icons/Ok.png);
}
''')
QMessageBox.information(None, "提示information", "消息",
QMessageBox.Close |
QMessageBox.Discard |
QMessageBox.Apply |
QMessageBox.Reset)
sys.exit()

View file

@ -0,0 +1,39 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Created on 2018年1月17日
@author: Irony."[讽刺]
@site: http://alyl.vip, http://orzorz.vip, https://coding.net/u/892768447, https://github.com/892768447
@email: 892768447@qq.com
@file: question
@description:
'''
__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com"
__Copyright__ = "Copyright (c) 2018 Irony.\"[讽刺]"
__Version__ = "Version 1.0"
import sys
from PyQt5.QtWidgets import QApplication, QMessageBox
app = QApplication(sys.argv)
app.setStyleSheet('''QDialogButtonBox {
dialogbuttonbox-buttons-have-icons: 1;
dialog-help-icon: url(../icons/Help.png);
dialog-yes-icon: url(../icons/Yes.png);
}
QMessageBox {
messagebox-question-icon: url(../icons/Ok.png);
}
''')
QMessageBox.question(None, "提示question", "消息",
QMessageBox.RestoreDefaults |
QMessageBox.Help |
QMessageBox.SaveAll |
QMessageBox.Yes |
QMessageBox.YesToAll)
sys.exit()

View file

@ -0,0 +1,39 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Created on 2018年1月17日
@author: Irony."[讽刺]
@site: http://alyl.vip, http://orzorz.vip, https://coding.net/u/892768447, https://github.com/892768447
@email: 892768447@qq.com
@file: warning
@description:
'''
__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com"
__Copyright__ = "Copyright (c) 2018 Irony.\"[讽刺]"
__Version__ = "Version 1.0"
import sys
from PyQt5.QtWidgets import QApplication, QMessageBox
app = QApplication(sys.argv)
app.setStyleSheet('''QDialogButtonBox {
dialogbuttonbox-buttons-have-icons: 1;
dialog-no-icon: url(../icons/No.png);
dialog-abort-icon: url(../icons/Abort.png);
dialog-retry-icon: url(../icons/Retry.png);
dialog-ignore-icon: url(../icons/Ignore.png);
}
QMessageBox {
messagebox-warning-icon: url(../icons/Ok.png);
}
''')
QMessageBox.warning(None, "提示warning", "消息",
QMessageBox.No |
QMessageBox.NoToAll |
QMessageBox.Abort |
QMessageBox.Retry |
QMessageBox.Ignore)
sys.exit()

View file

@ -0,0 +1,7 @@
# 方案二
截图
![critical](ScreenShot/critical.png)
![information](ScreenShot/information.png)
![question](ScreenShot/question.png)
![warning](ScreenShot/warning.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

View file

@ -0,0 +1,71 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Created on 2018年1月17日
@author: Irony."[讽刺]
@site: http://alyl.vip, http://orzorz.vip, https://coding.net/u/892768447, https://github.com/892768447
@email: 892768447@qq.com
@file: critical
@description:
'''
__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com"
__Copyright__ = "Copyright (c) 2018 Irony.\"[讽刺]"
__Version__ = "Version 1.0"
import sys
from PyQt5.QtWidgets import QApplication, QMessageBox
app = QApplication(sys.argv)
app.setStyleSheet('''
QPushButton[text="OK"] {
background: red;
qproperty-icon: url(../icons/Ok.png);
}
QPushButton[text="OK"]:hover {
background: darkRed;
}
QPushButton[text="Open"] {
background: green;
qproperty-icon: url(../icons/Open.png);
}
QPushButton[text="Open"]:hover {
background: darkGreen;
}
QPushButton[text="Save"] {
background: blue;
qproperty-icon: url(../icons/Save.png);
}
QPushButton[text="Save"]:hover {
background: darkBlue;
}
QPushButton[text="Cancel"] {
background: cyan;
qproperty-icon: url(../icons/Cancel.png);
}
QPushButton[text="Cancel"]:hover {
background: darkCyan;
}
QMessageBox {
messagebox-critical-icon: url(../icons/Close.png);
}
QMessageBox QPushButton {
min-width: 95px;
min-height: 30px;
border-radius: 5px;
}
''')
QMessageBox.critical(None, "提示critical", "消息",
QMessageBox.Ok |
QMessageBox.Open |
QMessageBox.Save |
QMessageBox.Cancel)
sys.exit()

View file

@ -0,0 +1,71 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Created on 2018年1月17日
@author: Irony."[讽刺]
@site: http://alyl.vip, http://orzorz.vip, https://coding.net/u/892768447, https://github.com/892768447
@email: 892768447@qq.com
@file: information
@description:
'''
__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com"
__Copyright__ = "Copyright (c) 2018 Irony.\"[讽刺]"
__Version__ = "Version 1.0"
import sys
from PyQt5.QtWidgets import QApplication, QMessageBox
app = QApplication(sys.argv)
app.setStyleSheet('''
QPushButton[text="Close"] {
background: red;
qproperty-icon: url(../icons/Close.png);
}
QPushButton[text="Close"]:hover {
background: darkRed;
}
QPushButton[text="Discard"] {
background: green;
qproperty-icon: url(../icons/Discard.png);
}
QPushButton[text="Discard"]:hover {
background: darkGreen;
}
QPushButton[text="Apply"] {
background: blue;
qproperty-icon: url(../icons/Apply.png);
}
QPushButton[text="Apply"]:hover {
background: darkBlue;
}
QPushButton[text="Reset"] {
background: cyan;
qproperty-icon: url(../icons/Reset.png);
}
QPushButton[text="Reset"]:hover {
background: darkCyan;
}
QMessageBox {
messagebox-information-icon: url(../icons/Close.png);
}
QMessageBox QPushButton {
min-width: 95px;
min-height: 30px;
border-radius: 5px;
}
''')
QMessageBox.information(None, "提示information", "消息",
QMessageBox.Close |
QMessageBox.Discard |
QMessageBox.Apply |
QMessageBox.Reset)
sys.exit()

View file

@ -0,0 +1,80 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Created on 2018年1月17日
@author: Irony."[讽刺]
@site: http://alyl.vip, http://orzorz.vip, https://coding.net/u/892768447, https://github.com/892768447
@email: 892768447@qq.com
@file: question
@description:
'''
__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com"
__Copyright__ = "Copyright (c) 2018 Irony.\"[讽刺]"
__Version__ = "Version 1.0"
import sys
from PyQt5.QtWidgets import QApplication, QMessageBox
app = QApplication(sys.argv)
app.setStyleSheet('''
QPushButton[text="Restore Defaults"] {
background: red;
qproperty-icon: url(../icons/RestoreDefaults.png);
}
QPushButton[text="Restore Defaults"]:hover {
background: darkRed;
}
QPushButton[text="Help"] {
background: green;
qproperty-icon: url(../icons/Help.png);
}
QPushButton[text="Help"]:hover {
background: darkGreen;
}
QPushButton[text="Save All"] {
background: blue;
qproperty-icon: url(../icons/SaveAll.png);
}
QPushButton[text="Save All"]:hover {
background: darkBlue;
}
QPushButton[text="&Yes"] {
background: cyan;
qproperty-icon: url(../icons/Yes.png);
}
QPushButton[text="&Yes"]:hover {
background: darkCyan;
}
QPushButton[text="Yes to &All"] {
background: magenta;
qproperty-icon: url(../icons/YesToAll.png);
}
QPushButton[text="Yes to &All"]:hover {
background: darkMegenta;
}
QMessageBox {
messagebox-question-icon: url(../icons/Close.png);
}
QMessageBox QPushButton {
min-width: 95px;
min-height: 30px;
border-radius: 5px;
}
''')
QMessageBox.question(None, "提示question", "消息",
QMessageBox.RestoreDefaults |
QMessageBox.Help |
QMessageBox.SaveAll |
QMessageBox.Yes |
QMessageBox.YesToAll)
sys.exit()

View file

@ -0,0 +1,84 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Created on 2018年1月17日
@author: Irony."[讽刺]
@site: http://alyl.vip, http://orzorz.vip, https://coding.net/u/892768447, https://github.com/892768447
@email: 892768447@qq.com
@file: warning
@description:
'''
__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: 892768447@qq.com"
__Copyright__ = "Copyright (c) 2018 Irony.\"[讽刺]"
__Version__ = "Version 1.0"
import sys
from PyQt5.QtWidgets import QApplication, QMessageBox
app = QApplication(sys.argv)
app.setStyleSheet('''
QPushButton[text="&No"] {
background: red;
qproperty-icon: url(../icons/No.png);
}
QPushButton[text="&No"]:hover {
background: darkRed;
}
QPushButton[text="N&o to All"] {
background: green;
qproperty-icon: url(../icons/NoToAll.png);
}
QPushButton[text="N&o to All"]:hover {
background: darkGreen;
}
QPushButton[text="Abort"] {
background: blue;
qproperty-icon: url(../icons/Abort.png);
}
QPushButton[text="Abort"]:hover {
background: darkBlue;
}
QPushButton[text="Retry"] {
background: cyan;
qproperty-icon: url(../icons/Retry.png);
}
QPushButton[text="Retry"]:hover {
background: darkCyan;
}
QPushButton[text="Ignore"] {
background: magenta;
qproperty-icon: url(../icons/Ignore.png);
}
QPushButton[text="Ignore"]:hover {
background: darkMegenta;
}
QMessageBox {
messagebox-warning-icon: url(../icons/No.png);
}
QMessageBox QPushButton {
min-width: 95px;
min-height: 30px;
border-radius: 5px;
}
QMessageBox QLabel {
color: red;
}
''')
QMessageBox.warning(None, "提示warning", "消息",
QMessageBox.No |
QMessageBox.NoToAll |
QMessageBox.Abort |
QMessageBox.Retry |
QMessageBox.Ignore)
sys.exit()

5
界面美化/README.md Normal file
View file

@ -0,0 +1,5 @@
# 通过QSS或者重绘对界面进行美化
### [1.QMessageBox样式](QMessageBox样式/)
- [1.1 方案一](QMessageBox样式/方案一)
- [1.2 方案二](QMessageBox样式/方案二)