Python Forum
PySide6 QFontDialog - bug or just me? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: PySide6 QFontDialog - bug or just me? (/thread-39256.html)



PySide6 QFontDialog - bug or just me? - PatM - Jan-21-2023

I have a qfontdialog that works ALMOST perfectly BUT I am having one issue.

When I first start the program I use
self.font = QFont()
self.font.setFamily("Sans")
self.font.setPointSize(15)

(and later)

        print("Font is", self.font)
        fdlg = QFontDialog()
        fdlg.setCurrentFont(self.font)
        fdlg.exec()
        font = fdlg.currentFont()
        if font:
            print("Change to", font)
            self.font = font
            Settings.fontFamily = self.font.family()
            Settings.fontSize = self.font.pointSize()
            self.getCaptionedImage()
[
The problem is that the dialog doesn't show any selected font (No line highlighted), But if I change to "Serif" then one is highlighted. If I run this and choose a diffferent font then when I reopen that font is highlighted. EXCEPT not if I choose "Sans Regular", that results in no selected font after I open a third time.

Seems like a bug where the system ignores Sans Regular but is it really?


RE: PySide6 QFontDialog - bug or just me? - Axel_Erfurt - Jan-22-2023

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.


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()