Reputation: 946
I'm having trouble here trying to set my Qlabel size to be bigger. Here is my code. I'm not sure what to do. I have tried lots...
def __init__(self, parent=None):
super(UICreator, self).__init__(parent)
self.Creator = QPushButton("YouTube", self)
self.Creator.resize(100, 40)
self.Creator.move(25, 50)
self.CreatorB2 = QPushButton("Twitter", self)
self.CreatorB2.resize(100, 40)
self.CreatorB2.move(275, 50)
self.CreatorL = QLabel("Created By:", self)
self.CreatorL.resize(100, 100)
self.CreatorL.move(20, 300)
Upvotes: 2
Views: 28353
Reputation: 1209
setGeometry
works perfectly unless you're using a layout where the dimensions need to be something specific, for which I use setFixedSize
This should help guarantee that your widget doesn't get unintentionally compressed or expanded due to a grid layout or something like that.
So it'd be something like this:
from PyQt5 import QtWidgets
my_label = QtWidgets.QLabel()
my_label.setText('My Label')
my_label.setFixedSize(50, 10)
Upvotes: 3
Reputation: 5704
If you're using PyQt4 then make sure you imported:
from PyQt4 import QtCore
then add this line to set size of the label:
self.CreatorL = QLabel("Created By:", self)
self.CreatorL.setGeometry(QtCore.QRect(70, 80, 100, 100)) #(x, y, width, height)
Upvotes: 6
Reputation: 21
To Add to Achilles comment since I foukd this useful...
the values actually go (x, y, width, height)
if you want to do a relative change then something like this will work:
self.CreatorL = QLabel("Created By:", self)
self.CreatorL.setGeometry(QtCore.QRect(self.CreatorL.x()+50, self.CreatorL.y(), self.CreatorL.width(), self.CreatorL.height()))
where this example will move the label 50 pixels to the right. Self.CreatorL can be replaced by the name of the label object.
Upvotes: 1