'multiple fonts in pyqt5?
I made a Gui in qt designer and I was wondering if I could add multiple fonts so that it works on multiple Operating systems.
I'm thinking of something like this:
<span style="font-family: arial, helvetica ,sans-serif">
<font size="1">
[Country]
</font>
</span>
The fonts i want are Consolas, Menlo, DejaVu Sans Mono, monospace
Heres the python code for my gui so far:
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
if not MainWindow.objectName():
MainWindow.setObjectName(u"MainWindow")
MainWindow.resize(1000, 1000)
MainWindow.setMinimumSize(QSize(1000, 1000))
MainWindow.setWindowIcon(icon)
MainWindow.setStyleSheet(u"background-color: rgb(31, 36, 33);")
self.centralwidget = QWidget(MainWindow)
self.centralwidget.setObjectName(u"centralwidget")
self.welcomeMessage = QLabel(self.centralwidget)
self.welcomeMessage.setObjectName(u"welcomeMessage")
self.welcomeMessage.setGeometry(QRect(30, 160, 951, 41))
sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.welcomeMessage.sizePolicy().hasHeightForWidth())
self.welcomeMessage.setSizePolicy(sizePolicy)
self.welcomeMessage.setCursor(QCursor(Qt.ArrowCursor))
self.welcomeMessage.setFocusPolicy(Qt.NoFocus)
self.welcomeMessage.setLayoutDirection(Qt.LeftToRight)
self.welcomeMessage.setStyleSheet(u"font: 30pt \"Consolas\"; color: rgb(240, 240, 240);")
self.welcomeMessage.setTextFormat(Qt.AutoText)
self.welcomeMessage.setScaledContents(False)
self.welcomeMessage.setAlignment(Qt.AlignCenter)
self.welcomeMessage.setWordWrap(False)
self.welcomeMessage.setMargin(0)
self.welcomeMessage.setOpenExternalLinks(False)
self.pushButton = QPushButton(self.centralwidget)
self.pushButton.setObjectName(u"pushButton")
self.pushButton.setGeometry(QRect(160, 620, 681, 141))
self.pushButton.setStyleSheet(u"color: rgb(31, 36, 33); font: 20pt \"Consolas\"; background-color: rgb(240, 240, 240); \n"
"selection-color: rgb(41, 47, 43);\n"
"")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QMenuBar(MainWindow)
self.menubar.setObjectName(u"menubar")
self.menubar.setGeometry(QRect(0, 0, 1000, 26))
MainWindow.setMenuBar(self.menubar)
self.statusbar = QStatusBar(MainWindow)
self.statusbar.setObjectName(u"statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QMetaObject.connectSlotsByName(MainWindow)
# setupUi
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"Password Generator", None))
#if QT_CONFIG(whatsthis)
self.welcomeMessage.setWhatsThis("")
#endif // QT_CONFIG(whatsthis)
self.welcomeMessage.setText(QCoreApplication.translate("MainWindow", u"Welcome to the Password Generator!", None))
self.pushButton.setText(QCoreApplication.translate("MainWindow", u"Click here to generate a password!", None))
# retranslateUi
I havent tried using multiple fonts on it yet.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
