Skip to main content

PyQt font dialog and widget

Project description

pyqt-font-dialog

PyQt "select the font" dialog and widget

Requirements

PyQt5 >= 5.8

Setup

python -m pip install pyqt-font-dialog

Class/Method Overview

  • FontDialog(font: QFont = QFont('Arial', 10), title='Font') - font is font, title is title of the dialog.

    • getFont() - get the selected font.
  • FontWidget(font: QFont = QFont('Arial', 10))

    • fontChanged(QFont) - When current font item is changed, this will be emitted.

    • getFont() - get the selected font.

Usage

1. As a dialog

dialog = FontDialog(textEdit.currentFont())

reply = dialog.exec()

if reply == QDialog.Accepted:

    textEdit.setCurrentFont(dialog.getFont())

Preview

image

2. As a part of window

from PyQt5.QtWidgets import QMainWindow, QApplication, QHBoxLayout, QWidget, QTextEdit

from pyqt_font_dialog.fontWidget import FontWidget





class Window(QMainWindow):

    def __init__(self):

        super().__init__()

        self.__initUi()



    def __initUi(self):

        self.__te = QTextEdit()

        fontWidget = FontWidget()

        fontWidget.fontChanged.connect(self.fontChanged)

        lay = QHBoxLayout()

        lay.addWidget(self.__te)

        lay.addWidget(fontWidget)

        mainWidget = QWidget()

        mainWidget.setLayout(lay)

        self.setCentralWidget(mainWidget)



    def fontChanged(self, font):

        self.__te.selectAll()

        self.__te.setFont(font)

        cur = self.__te.textCursor()

        cur.clearSelection()

        self.__te.setTextCursor(cur)





if __name__ == "__main__":

    import sys



    app = QApplication(sys.argv)

    ex = Window()

    ex.show()

    sys.exit(app.exec_())

Preview

https://user-images.githubusercontent.com/55078043/189460933-387d3570-e153-4df9-8a21-d02a46fbfe64.mp4

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyqt-font-dialog-0.0.14.tar.gz (4.9 kB view hashes)

Uploaded Source

Built Distribution

pyqt_font_dialog-0.0.14-py3-none-any.whl (7.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page