Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set just `Widget` size?

Tags:

qt

pyqt

pyside

How can I set just Widget size?

My code:

from PySide.QtGui import QApplication, QWidget, QLabel
import sys
app = QApplication(sys.argv)

mainWindow = QWidget()
gameWidget = QWidget(mainWindow)

#gameWidget.setGeometry(gameWidth, gameHeight) <-- I want to set size of gameWidget such like this. How can I do this.
gameWidget.move(100,0)
gameLabel = QLabel("This is game widget", gameWidget)

mainWindow.show()

Output:

enter image description here

Description:

This will create Window that contain Widget. I want to set this Widget size. I know There is a method Widget.setGeometry, but it takes 4 parameter (x, y, width, height). I want a method like Widget.setGeometry which takes just size parameter (width, height).

P.S. Feel free to modify my question. Because I'm always learning English!!

Thanks.

like image 292
Kei Minagawa Avatar asked Jun 26 '14 03:06

Kei Minagawa


People also ask

How do I add a small widget to my home screen?

Long-press on an empty area of your iPhone's home screen. When the app icons start to wobble, as you'll have seen when rearranging apps, you'll now see a small + icon appear in the top left corner of your phone. Tap it and it'll bring up the widgets menu. This tiny plus that appears when you long-press on an app?


1 Answers

Just use QWidget.resize(weight, height).

For example:

gameLabel.resize(200, 100);

Besides, you can also use QWidget.sizeHint() to get a proper size automatically, for example:

gameLabel.resize(gameLabel.sizeHint());
like image 69
Tay2510 Avatar answered Sep 21 '22 00:09

Tay2510