Created
January 1, 2021 05:58
-
-
Save Park-Developer/ea9e3d85409a1c97959263a293b90b28 to your computer and use it in GitHub Desktop.
pyqt5 : Qlabel size setting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rom PyQt5.QtWidgets import * | |
from PyQt5 import QtCore | |
from PyQt5.QtGui import * | |
import sys | |
class Window(QMainWindow): | |
def __init__(self): | |
super().__init__() | |
# set the title | |
self.setWindowTitle("Label") | |
# setting the geometry of window | |
self.setGeometry(0, 0, 400, 300) | |
# creating a label widget | |
self.label_1 = QLabel("== Normal Label ====", self) | |
# moving position | |
self.label_1.move(100, 100) | |
# setting up border | |
self.label_1.setStyleSheet("border: 1px solid black;") | |
# creating a label widget | |
self.label_2 = QLabel("====== Adjusted label =====", self) | |
# moving position | |
self.label_2.move(100, 150) | |
# setting up border | |
self.label_2.setStyleSheet("border: 1px solid black;") | |
# adjusting the size of label | |
self.label_2.adjustSize() | |
# show all the widgets | |
self.show() | |
# create pyqt5 app | |
App = QApplication(sys.argv) | |
# create the instance of our Window | |
window = Window() | |
# start the app | |
sys.exit(App.exec()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[Reference]
https://www.geeksforgeeks.org/pyqt5-how-to-auto-resize-label-adjustsize-qlabel/