Skip to content

Instantly share code, notes, and snippets.

@saleph
Created September 4, 2015 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saleph/0d587195d6b556139a5c to your computer and use it in GitHub Desktop.
Save saleph/0d587195d6b556139a5c to your computer and use it in GitHub Desktop.
[qt5] font dialog
import sys
from PyQt5.QtWidgets import (QWidget, QVBoxLayout, QPushButton,
QSizePolicy, QLabel, QFontDialog, QApplication)
class Example(QWidget):
def __init__(self):
super().__init__()
self.init_ui()
def init_ui(self):
v_box = QVBoxLayout()
btn = QPushButton('Dialog', self)
btn.setSizePolicy(QSizePolicy.Fixed,
QSizePolicy.Fixed)
btn.move(20, 20)
v_box.addWidget(btn)
btn.clicked.connect(self.show_dialog)
self.lbl = QLabel('Knowledge only matters', self)
self.lbl.move(130, 20)
v_box.addWidget(self.lbl)
self.setLayout(v_box)
self.setGeometry(300, 300, 250, 180)
self.setWindowTitle('Font dialog')
self.show()
def show_dialog(self):
font, ok = QFontDialog.getFont()
if ok:
self.lbl.setFont(font)
if __name__ == "__main__":
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment