Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PYQT layout and setgeometry basic overview

Tags:

python

pyqt

Im trying to get my qsplitlines to set to a basic shape upon startup of my program. I have been playing around with the 4 numbers in setgerometry(x, x, x, x) Could I get a simple explanation of what they correlate too?

From top, ?, From left, ?

(down starting from top, from left, continuing, how many rows it spas across)

hbox = QtGui.QHBoxLayout(self)

topleft = QtGui.QFrame(self)
topleft.setFrameShape(QtGui.QFrame.StyledPanel)
topleft.setGeometry(0, 0, 300, 0)

topright = QtGui.QFrame(self)
topright.setFrameShape(QtGui.QFrame.StyledPanel)
topright.setGeometry(0, 320, 1000, 0)

bottom = QtGui.QFrame(self)
bottom.setFrameShape(QtGui.QFrame.StyledPanel)
bottom.setGeometry(1210, 0, 1280, 0)

splitter1 = QtGui.QSplitter(QtCore.Qt.Horizontal)
splitter1.addWidget(topleft)
splitter1.addWidget(topright)

splitter2 = QtGui.QSplitter(QtCore.Qt.Vertical)
splitter2.addWidget(splitter1)
splitter2.addWidget(bottom)

hbox.addWidget(splitter2)

self.setLayout(hbox)
#QtGui.QApplication.setStyle(QtGui.QStyleFactory.create('Cleanlooks'))
like image 654
Anekdotin Avatar asked Sep 25 '15 17:09

Anekdotin


People also ask

What is layout in PyQt?

In PyQt, layout managers are classes that provide the required functionality to automatically manage the size, position, and resizing behavior of the widgets in the layout. With layout managers, you can automatically arrange child widgets within any parent, or container, widget.

What is setGeometry in PyQt5?

setGeometry() method is used to set up the geometry of the PyQt5 window it self. Syntax : window.setGeometry(x, y, width, height)

Is PyQt a library or framework?

Getting to Know PyQt. PyQt is a Python binding for Qt, which is a set of C++ libraries and development tools providing platform-independent abstractions for graphical user interfaces (GUIs).

What is QWidget in PyQt?

The QWidget class is the base class of all user interface objects.


1 Answers

I'm going to show you how to walk through the documentation before the answer at the bottom. It'll help you in the long run.

Start with the QFrame documentation. You are looking for a setGeometry method. You'll notice that there isn't one, but the QFrame does inherit from the QWidget

Going to the QWidget documentation you'll find that there is are two setGeometry methods

QWidget.setGeometry (self, QRect)

and

QWidget.setGeometry (self, int ax, int ay, int aw, int ah)

The first one takes a QRect and the second takes series of integers. Let's look at the QRect docs too:

A QRect can be constructed with a set of left, top, width and height integers

This lines up with the series of integers the other method takes. This image from the Qt Documentation helps explain it:

Window Geometry

Thus, your integers are:

  • X coordinate
  • Y coordinate
  • Width of the frame
  • Height of the frame
like image 119
Andy Avatar answered Sep 20 '22 07:09

Andy