PyQt5: Text seems to overlap
Unsolved
Qt for Python
-
Hi, I wanted to make the QLabel on the bottom of a QLabel, somehow ended up having this.
main
snippet:def main(): app = QtWidgets.QApplication([]) window = QtWidgets.QWidget() window.setWindowTitle("kabantu") label = QtWidgets.QLabel(window) pixel = QtGui.QPixmap.fromImage(QtGui.QImage("kabantu.png")) label.setPixmap(pixel) label.setFixedSize(380, 136) label.setScaledContents(True) titleLabel = QtWidgets.QLabel(window) titleLabel.setText("kabantu 26.04 lts installer") titleLabel.setStyleSheet("font-size: 20px;") titleLabel.setAlignment(QtCore.Qt.AlignCenter) font = titleLabel.font() font.setBold(True) layout = QtWidgets.QVBoxLayout() layout.setAlignment(QtCore.Qt.AlignCenter) layout.addWidget(label) layout.addWidget(titleLabel) window.setWindowIcon(QtGui.QIcon("./kabantu.png")) window.setFixedSize(400, 200) window.show() app.exec_()
-
@zeankundev
You add your widgets to a layout, but you don't seem to put the layout anywhere on the window? -
@zeankundev
One of:window.setLayout(layout)
or when constructing the layout:
layout = QtWidgets.QVBoxLayout(window)
On a quite separate matter: in two places you use
"kabantu.png"
and"./kabantu.png"
. Be careful: these are relative paths, your code relies on the current working directory being somewhere (same place as where your.py
file is?) for these to work. I do not know that Python guarantees to set the working directory to where the script is when running it, I do not think it does. Consider using an absolute path, e.g. one constructed from determining where the.py
file is at runtime?