Issue
In PyQt5
, I found that equal length strings with whitespaces have different final display length:
while the desired output should be like:
123456789
1 3456789
1 456789
1 56789
I found this issue not only exists in QComboBox
, but also in other multi-row widgets. Fixing length, such as {:15s}
, also cause the issue.
Is there a way to display as the desired output?
A minimal example of the described issue:
from PyQt5.QtWidgets import QApplication, QComboBox, QMainWindow
import sys
class Window(QMainWindow):
def __init__(self):
super().__init__()
self.combo_box = QComboBox(self)
a = ["123456789", "1 3456789", "1 456789", "1 56789"]
self.combo_box.addItems(a)
self.show()
App = QApplication(sys.argv)
window = Window()
sys.exit(App.exec())
Solution
The misalignment is caused by the font as it doesn't give you the same space between the letters and the spaces. The solution is to use a font like "monospace":
from PyQt5.QtGui import QFont
font = QFont("monospace")
self.combo_box.setFont(font)
Answered By - eyllanesc
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.