python-3.x - 在子类 QFontDialog 中获取选定的字体
问题描述
我正在尝试继承 QFontDialog 并希望检索所选字体的特征。如果我使用 getFont() 首先出现一个 QFontDialog 窗口,...我肯定做错了什么。
这是我的示例代码:
from PyQt5.QtWidgets import (QFontDialog, QPushButton,
QMainWindow, QApplication,
QTabWidget, QWidget, QVBoxLayout)
import sys
class FontSelection(QFontDialog) :
def __init__(self, parent=None):
super(FontSelection, self).__init__(parent)
self.setOption(self.DontUseNativeDialog, True)
self.bouton = self.findChildren(QPushButton)
self.intitule_bouton = self.bouton[0].text().lower()
self.ouvertureBouton = [x for x in self.bouton if self.intitule_bouton in str(x.text()).lower()][0]
self.ouvertureBouton.clicked.disconnect()
self.ouvertureBouton.clicked.connect(self.font_recup)
def font_recup(self) :
self.font_capture()
def font_capture(self) :
if self.intitule_bouton in ['ok', '&ok'] :
font, self.intitule_bouton = self.getFont()
print(font)
class MainQFontDialogTry(QMainWindow):
def __init__(self):
super(MainQFontDialogTry, self).__init__()
self.setWindowTitle('QFontDialog subclassed try')
self.setGeometry(0, 0, 1000, 760)
self.setMinimumSize(1000, 760)
self.tab_widget = QTabWidget()
self.win_widget_1 = FontSelection(self)
widget = QWidget()
layout = QVBoxLayout(widget)
self.tab_widget.addTab(self.win_widget_1, "QFontDialog Tab")
layout.addWidget(self.tab_widget)
self.setCentralWidget(widget)
self.qfont = FontSelection()
self.qfont.font_recup()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MainQFontDialogTry()
ex.show()
sys.exit(app.exec_())
解决方案
推荐阅读
- virtual-machine - 适用于 Windows Server 的 KVM 虚拟化鼠标不稳定
- java - JPA 查询或自定义查询根据两个表中的搜索词查找结果
- matlab - 你能用 ~any() 帮助我理解这两条 matlab 行吗
- python - 在文本文件python tkinter中生成新行的条目末尾的随机空间
- php - 如何打印最多 10 个不在数组中的数字?
- php - 将数组分解为多维数组(父->子->子子)
- permissions - WSL 2 复制具有保留属性的字符设备文件失败
- kubernetes - 什么会导致部署中的 pod 挂载卷
- javascript - 如何使用 HTML 中选中的 1 或 2 个可能的框制作清单
- amazon-web-services - AWS S3 存储桶:什么是 TagStorage-TagHrs