Jan-22-2023, 01:29 PM
I once made a test (Linux LMDE5).
True, sans or sans regular will not bring the desired result.
It works with a font that has a name before Sans.
True, sans or sans regular will not bring the desired result.
It works with a font that has a name before Sans.
from PySide6.QtWidgets import (QWidget, QVBoxLayout, QPushButton, QSizePolicy, QLabel, QFontDialog, QApplication) from PySide6.QtGui import QFont import sys class Example(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): self.font = QFont("Noto Sans [Regular]", 13) vbox = QVBoxLayout() btn = QPushButton('Dialog', self) btn.setFixedSize(100, 26) vbox.addWidget(btn) btn.clicked.connect(self.showDialog) self.lbl = QLabel('This Is A Font Test', self) vbox.addWidget(self.lbl) self.setLayout(vbox) self.setGeometry(300, 300, 450, 350) self.setWindowTitle('Font Test') self.show() def showDialog(self): print("Font is", self.font.family(), self.font.weight(), self.font.pointSize()) fdlg = QFontDialog() fdlg.setCurrentFont(self.font) fdlg.exec() font = fdlg.currentFont() if font: print("Change to", font.family(), font.weight(), font.pointSize()) self.lbl.setFont(font) def main(): app = QApplication(sys.argv) ex = Example() sys.exit(app.exec()) if __name__ == '__main__': main()