Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

PySide window does not resize to fit screen

837 views
Skip to first unread message

Hedieh Ebrahimi

unread,
Oct 1, 2015, 9:44:46 AM10/1/15
to
Dear all,

I am using Pyside to create a user interface for my app.
The app works fine on my computer with big screen, but when I take it to my laptop with smaller screen size, it does not resize to match the screen size.

How can I make my main widget get some information about the screen size and resize automatically?

Thanks in Advance for your answers.

Chris Warrick

unread,
Oct 1, 2015, 11:07:53 AM10/1/15
to Hedieh Ebrahimi, pytho...@python.org
> --
> https://mail.python.org/mailman/listinfo/python-list

The correct way to do this is to lay your application out using a
layout. The available layouts are:

* QHBoxLayout
* QVBoxLayout
* QGridLayout
* QFormLayout

The exact layout to use depends on your needs.

What are you using to create your Qt code? Are you using Qt Designer
or are you writing the code by hand? If you are using Qt Designer,
use the “Lay Out…” buttons in the Form menu or on the tool bar. If
you are writing Qt code by hand, it looks roughly like this (for a
VBox; Grid and Form are more complicated as they involve positioning):

lay = QtGui.QVBoxLayout(self) # your central widget, dialog, main
window — whichever one exists
btn = QtGui.QButton("Hello", lay)
lay.addWidget(btn)

Please check with Qt documentation for more details

--
Chris Warrick <https://chriswarrick.com/>
PGP: 5EAAEA16

Laura Creighton

unread,
Oct 1, 2015, 12:19:38 PM10/1/15
to Hedieh Ebrahimi, pytho...@python.org
screenGeometry = QApplication.instance().desktop().screenGeometry()
to find out your desktop size in pixels.
availGeometry = QApplication.instance().desktop().availableGeometry()
is the same thing minus the space for the task bar, so maybe more
useful.

width, height = availGeometry.width(), availGeometry.height()

Finding out what pyside thinks the size is can be useful for debugging
problems, but this stuff should already be happening automatically. There is
something not quite right with your layout, and brutally resizing things
by hand is treating the symptom, not the cause.

Laura

Hedieh Ebrahimi

unread,
Oct 2, 2015, 9:11:38 AM10/2/15
to
Thanks Laura,

In my user interface I have many group boxes that are located inside the main widget. All the group boxes and their child widgets have fixed sizes.

How can I use the width and height I get from availableGeometry or ScreenGeometry to multiply

screenGeometry = QApplication.instance().desktop().screenGeometry()
availGeometry = QApplication.instance().desktop().availableGeometry()
width, height = availGeometry.width(), availGeometry.height()

to resize my geometry by a ratio? Is this a good approach?

Chris Warrick

unread,
Oct 2, 2015, 9:26:05 AM10/2/15
to Hedieh Ebrahimi, pytho...@python.org
> --
> https://mail.python.org/mailman/listinfo/python-list

This is NOT a good approach. A good approach involves using a layout.
See my previous e-mail for details.

Geometry is not going to help you here, especially since you would
need a ton of code to resize everything on **any** window size change
event. And you especially do not need the screen size, because it
would still hinder changing window sizes.

Hedieh Ebrahimi

unread,
Oct 5, 2015, 4:19:01 AM10/5/15
to
Hi Chris,

Thanks for your answer. I get your point now.
Unfortunately there are not layouts in my user interface.
Smaller widget have been grouped using group boxes and then all these group boxes are put on the central widget.

I would like to recreate my user interface using one of the designer software that exist.

Could you recommend any free designer software that I can create my user interface with?

Thank you

Laura Creighton

unread,
Oct 5, 2015, 6:51:31 AM10/5/15
to pytho...@python.org
In a message of Mon, 05 Oct 2015 01:18:33 -0700, Hedieh Ebrahimi writes:
>Could you recommend any free designer software that I can create my user interface with?
>
>Thank you

Qt Designer works with PySide.
http://doc.qt.io/qt-5/designer-quick-start.html

Laura

Hedieh Ebrahimi

unread,
Oct 5, 2015, 7:20:59 AM10/5/15
to
is this free to use for commercial use?

Chris Warrick

unread,
Oct 5, 2015, 9:32:53 AM10/5/15
to Hedieh Ebrahimi, pytho...@python.org
On 5 October 2015 at 13:20, Hedieh Ebrahimi <hem...@gmail.com> wrote:
> is this free to use for commercial use?
> --
> https://mail.python.org/mailman/listinfo/python-list

Yeah, you can use Qt Designer to create a nice layout and the
pyside-uic tool to generate code (that you will need to clean up
later).

Michael Torrie

unread,
Oct 5, 2015, 12:29:08 PM10/5/15
to pytho...@python.org
On 10/05/2015 05:20 AM, Hedieh Ebrahimi wrote:
> is this free to use for commercial use?

Yes of course. There's also the newer Qt Creator program if you want to
use Qt 5. The license of the Designer and Creator programs does not
apply to the output of these programs (the .ui XML files).

You'll want to read up on the documentation. Here's a couple of links
for starters:

http://doc.qt.io/qt-4.8/designer-layouts.html
https://wiki.qt.io/QtCreator_and_PySide (works with .ui files from
Designer also)

Even if you don't use a GUI designer, you should construct your GUI with
layout managers so that your interfaces can adjust and look good on a
variety of screen sizes and DPI. It's pretty simple once you wrap your
brain around the idea.

Another method of working with .ui files it to load them at runtime:
https://srinikom.github.io/pyside-docs/PySide/QtUiTools/QUiLoader.html


wxjm...@gmail.com

unread,
Oct 5, 2015, 2:28:47 PM10/5/15
to
And PySide does not work properly with Python 3.3+.

Heli

unread,
Nov 14, 2017, 9:53:14 AM11/14/17
to
Hi Chris and others,

I have re-designed my user interface to include layouts and now it fits the screen perfectly.

Thanks a lot for all your help on this thread,
Best
0 new messages