Created
September 4, 2015 10:56
-
-
Save saleph/0d587195d6b556139a5c to your computer and use it in GitHub Desktop.
[qt5] font dialog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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