def __init__(self, key_obj):
super().__init__()
self._obj = key_obj
self.setText(self.key)
self.setToolTip(self.key)
font = QtGui.QFontDatabase.FixedFont
font = QtGui.QFontDatabase().systemFont(font)
self.setFont(font)
icon = QtWidgets.QFileIconProvider.File
icon = QtWidgets.QFileIconProvider().icon(icon)
self.setIcon(icon)
self.setSelectable(True)
self.setEditable(False)
self.setEnabled(True)
self.setFlags(self.flags() | Qt.Qt.ItemNeverHasChildren)
python类QFontDatabase()的实例源码
def __init__(self, document):
"""
Args:
document (Document):
"""
super().__init__(None) # no brown object exists for this
# TODO: make one
self.document = document
self.app = QtWidgets.QApplication([])
self.main_window = MainWindow()
self.scene = QtWidgets.QGraphicsScene()
self.view = self.main_window.graphicsView
self.view.setScene(self.scene)
self.registered_music_fonts = {}
self.font_database = QtGui.QFontDatabase()
######## PUBLIC METHODS ########
def __init__(self, parent=None, title="Console Output"):
"""Constructor for QConsoleOutputWidget.
Keyword Arguments:
parent -- parent widget for this widget (default: None)
title -- Title for the window (default: "Console Output")
Example:
QConsoleOutputWidget()
QConsoleOutputWidget(title="Program Output")
"""
super().__init__(parent)
self.setWindowTitle(str(title))
self.setGeometry(800, 400, 600, 200)
QtGui.QFontDatabase().addApplicationFont(Resources.monspaceFont)
self.messageQueue = []
self.__processes = []
self.__processThreads = []
self.__printLock = threading.Lock()
self.__initUI()
def __init__(self, process, parent=None):
"""Constructor for QConsoleInputWidget
Arguments:
process -- process to send stdin to
Keyword Arguments:
parent -- parent widget for this widget (default: None)
Example:
QConsoleInputWidget()
"""
super().__init__(parent)
QtGui.QFontDatabase().addApplicationFont(Resources.monspaceFont)
self.__initUI()
self.process = process
def __init__(self, parent):
super().__init__('Font', parent)
self.font_name_edit = QtWidgets.QComboBox(
self,
editable=False,
sizePolicy=QtWidgets.QSizePolicy(
QtWidgets.QSizePolicy.Expanding,
QtWidgets.QSizePolicy.Preferred),
insertPolicy=QtWidgets.QComboBox.NoInsert)
self.font_size_edit = QtWidgets.QSpinBox(self, minimum=0)
self.bold_checkbox = QtWidgets.QCheckBox('Bold', self)
self.italic_checkbox = QtWidgets.QCheckBox('Italic', self)
self.underline_checkbox = QtWidgets.QCheckBox('Underline', self)
self.strike_out_checkbox = QtWidgets.QCheckBox('Strike-out', self)
all_fonts = QtGui.QFontDatabase().families()
self.font_name_edit.addItems(all_fonts)
layout = QtWidgets.QGridLayout(self)
layout.setColumnStretch(0, 1)
layout.setColumnStretch(1, 2)
layout.addWidget(QtWidgets.QLabel('Name:', self), 0, 0)
layout.addWidget(self.font_name_edit, 0, 1)
layout.addWidget(QtWidgets.QLabel('Size:', self), 1, 0)
layout.addWidget(self.font_size_edit, 1, 1)
layout.addWidget(QtWidgets.QLabel('Style:', self), 2, 0)
layout.addWidget(self.bold_checkbox, 2, 1)
layout.addWidget(self.italic_checkbox, 3, 1)
layout.addWidget(self.underline_checkbox, 4, 1)
layout.addWidget(self.strike_out_checkbox, 5, 1)
def main():
# Set a unique id to BATS
import ctypes
appid = 'bats.1.1.0'
# Check the platform. If windows, set an ID so it will be in the task bar.
if sys.platform == 'win32':
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(appid)
elif sys.platform == 'linux':
pass
elif sys.platform == 'darwin':
pass
else:
sys.stdout.write("The application is not supported in this system")
pass
# Create the application
app = QtWidgets.QApplication(['Bayesian Adaptive Trial Simulator'])
# Add icon for the application
app_icon = QtGui.QIcon()
app_icon.addFile(":/resources/bcts.png", QtCore.QSize(16,16))
app_icon.addFile(":/resources/bcts.png", QtCore.QSize(24,24))
app_icon.addFile(":/resources/bcts.png", QtCore.QSize(32,32))
app_icon.addFile(":/resources/bcts.png", QtCore.QSize(48,48))
app_icon.addFile(":/resources/bcts.png", QtCore.QSize(256,256))
app.setWindowIcon(app_icon)
# Add font to the font database
QtGui.QFontDatabase().addApplicationFont(":/resources/font/Caviar_Dreams_Bold.ttf")
QtGui.QFontDatabase().addApplicationFont(":/resources/font/PTsans.ttf")
# Initialize the GUI
window = BATSWindow()
window.show()
# Run the app
sys.exit(app.exec_())
# Initialize of the app