Let's say that I have 3 labels and each one is supposed to have different sized text. Inspect this example code:
import sys
from PySide2 import QtCore, QtGui, QtWidgets
def Fonty():
ok, font = QtWidgets.QFontDialog.getFont(tableWidget)
if ok:
app.setFont(font)
tableWidget.resizeColumnsToContents()
tableWidget.resizeRowsToContents()
app = QtWidgets.QApplication(sys.argv)
tableWidget = QtWidgets.QTableWidget()
tableWidget.setColumnCount(4)
tableWidget.setRowCount(1)
for x in range(3):
label = QtWidgets.QLabel(tableWidget)
font = QtGui.QFont()
size = 8 + (x * 2)
font.setPointSize(size)
label.setFont(font)
label.setText("Testing")
tableWidget.setCellWidget(0, x, label)
tableWidget.resizeColumnsToContents()
pushButton = QtWidgets.QPushButton()
pushButton.setText("Fonts")
pushButton.clicked.connect(Fonty)
tableWidget.setCellWidget(0, 3, pushButton)
tableWidget.resizeColumnsToContents()
tableWidget.show()
sys.exit(app.exec_())
The button labeled "Fonts" will open a standard Qt font dialog box. When I run this I can see that the headers of the table and the text in the button change size when I change the font size via the dialog box. But the labels that have a fixed font size don't change. What if I would like them to change in size as the font size changes? How do I "scale" the size of the font for these widgets?