Python Forum
PySide6 QFontDialog - bug or just me?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PySide6 QFontDialog - bug or just me?
#1
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?
Reply
#2
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()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  PySide6 - Connect to DBus signal - Correct syntax Drexel 1 575 Dec-18-2023, 08:03 AM
Last Post: Drexel
  PySide6 Copy and Past from clipboard to QTableWedget zinho 6 1,138 Dec-07-2023, 10:10 PM
Last Post: zinho
Bug [PyQt] Dinamically adding widgets to layout [PySide6] carecavoador 2 1,363 Jun-19-2023, 12:57 PM
Last Post: carecavoador
  Pyside6 Larz60+ 7 2,823 Nov-28-2022, 07:25 PM
Last Post: Larz60+
  [PySide6] Load ui with UiLoader catlessness 6 8,629 Nov-24-2021, 02:17 PM
Last Post: catlessness

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020