2

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)
Praveen
  • 6,872
  • 3
  • 43
  • 62
Tyrell
  • 896
  • 7
  • 15
  • 26
  • Just a question on the side: are you sure you want fixed geometry for all your widgets? Unless you have a strict display size writing scalable UI is the preferable way to go. Using a layout will take care of the resizing (though you can set the size policy of every widget to ensure a specific way of handling resize events for each of these). – rbaleksandar Dec 23 '16 at 07:07
  • What exactly do you mean by "bigger"? And what, specifically, have you tried that didn't work? – ekhumoro Dec 23 '16 at 18:30

3 Answers3

6

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)
frazii
  • 3
  • 3
Taufiq Rahman
  • 5,600
  • 2
  • 36
  • 44
3

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)
NL23codes
  • 1,181
  • 1
  • 14
  • 31
1

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.

Woody
  • 21
  • 5