In the following code, characterLabel
is small a bit.
But characterLabelEntire
is too big.
How to create QLabel
which just fits its text?
from PySide.QtCore import *
from PySide.QtGui import *
targetChar = unichr(0x0e0e)
# Setting
font = QFont()
font.setPointSize(50)
sizePolicy = QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum)
# Following code will create a character label.
# But it seems the size of the label is small a bit.
# Becasue some of the region of the character is lost.
characterLabel = QLabel(targetChar)
characterLabel.setFont(font)
characterLabel.setSizePolicy(sizePolicy)
# Following code will create a character label, but it's too big.
characterLabelEntire = QLabel(targetChar)
characterLabelEntire.setFont(font)
characterLabelEntire.setFixedSize(100, 100)
characterLabel.setSizePolicy(sizePolicy)
# Show and Raise
characterLabel.show()
characterLabelEntire.show()
characterLabel.raise_()
characterLabelEntire.raise_()
try:
app = QApplication([])
app.exec_()
except:
pass
It seems Exotic character designer break font rule?
I found the following article.
http://doc.qt.io/qt-4.8/qfontmetrics.html#descent
Anyway, in my environment(OS X 10.11), larger descent is needed to show the entire character image.
from PySide.QtCore import *
from PySide.QtGui import *
try:
app = QApplication([])
except:
pass
targetChar = unichr(0x0e0e)
# Setting
font = QFont()
font.setPointSize(100)
# Following code will create a character label.
characterLabel = QLabel(targetChar)
characterLabel.setFont(font)
fm = characterLabel.fontMetrics()
pixelsWide = fm.width(targetChar)
pixelsHigh = fm.ascent() + fm.descent() * 3
characterLabel.setFixedSize(pixelsWide, pixelsHigh)
characterLabel.show()
characterLabel.raise_()
try:
app.exec_()
except:
pass