Behavior of “geometry” Property and “show” Method in PySide


I am developing applications that runs on Linux and Windows using PySide. In the process, I recently, so embarrassed a lot for the behavior of the “geometry” property of QMainWindow differs between Windows and Linux, so I investigated in detail.

Introduction

I wanted to do the following.

After the minimize, maximize, and full screen sized the main window, I want to know the current size of the window by code.

By running the QWidget.showMaximized / Minimized / FullScreen method, it is possible to change the window size to be displayed. (In the reference, there is a description indicating that showFullScreen() may not work well with X Window. But there is no inconvenience for now in use my range.) However, as described below, to know the display size from the current code, it works well on Windows, but it did not work on Linux.

How to Investigate

I have created the program that, by running each method show, showMaximized, showMinimized, showFullScreen, showNormal and setGeometry for QMainWindow, you can see how “geometry” property change. (Because it is unable to verify the value while displaying the window if you run the method before event loop, I made the methods run with delay of 100msec by QTimer. (Because the windows are displayed, the screen flickers a little at run time.)

Result

Here are the results of running checkShow.py, in the above-mentioned, on Windows7, Xubunutu13.04 and Ubunutu13.04 in the same PC (with VirtualBox environment: Host Windows, Guset Linux) with a screen size of 1920×1080. I listed the value of the “geometry” of the property at each stage. (It cut the redundant part of the actual display.)

The values of the QRect are, the first two are the position (the coordinates of the upper left) and the following two are the size (width x length).

On Windows

On Xubuntu/Ubuntu

The results on Ubuntu and Xubuntu were the same.

Summary

From the above results, I’ve found the following facts about “geometry” property.

  • Both on Windows and Linux, the value before running show() is (0, 0, 640, 480). (I think that it is VGA size).
  • After running show(), size is changed to 200×100 on both OS. However, the display position differs by OS. On Linux, it is the upper-left corner. And on Windows, it is shifted slightly to the lower right.
  • On Windows, after running showMaximized/FullScreen/Normal, “geometry” is set to the size of the window that is actually displayed. However, on Linux, those methods do not change the “geometry”.(Display itself is changed to be maximize or full sized or normalized. These facts mean that the value of the “geometry” and the actual window that is displayed does not match.)
  • showMinimized() method does not change “geometry” on Windows (also Linux). Perhaps, it seems that minimize is equivalent to be invisible.
  • Of course, setGeometry change the “geometry” on both OS.

From these results, you can find that on Windows you can know the current window size from “geometry” property, but there is a possibility that the current window size does not match the “geometry” in the case of Linux. On Linux, if you want to match the window size and the “geometry”, you should culculate the size of your own and run setGeometry().

[Related Site]
junf/checkshow

[Related Articles]

[Referenced Sites]


Display Image While Sliding by PySide


I will describe, as can be seen well in the slide-show, how to display image while sliding in the vertical and horizontal by PySide. I also touched on the Qt-Properties.

Note: The code following, I have validated in Python3.3.

Put a “Label” to the Main Window

First, define a framework of the application. In the main window, try to place the “label” to display the image “hoge.jpg”. (Since slide later, please prepare the “hoge.jpg” not so large.) In addition, “setGeometry()” of line 13, is setting the size of the main window. Please give appropriate values for your environment.

When you run, it is as follows.
image

Deal With Qt-Property

To slide the “label” as defined here, you can use the animation technology. Animation in PySide is achieved by changing little by little “Properties” which QObject has.

“Properties” in Qt is designed so that it does not depend on the language, but its implementation seems to be somewhat different for each language. In PySide (Python), it is implemented as methods (so-called “Setter” and “Getter”). So, you do not know whether it is a “Property” while not see a reference in. If it is a property, it is in the description, such as “This property holds …”.

So, I think, if you look at the “Properties”, you had better to look at the reference of Qt (not PySide).

Define the Animation

Well, the purpose of this article, “slide” can be achieved by changing the “pos” property of QWidget. “pos” is a property of QPoint to retain the position of the upper-left corner of the object.

First, define QPropertyAnimation object.

It means that animates the “pos” property of the “label” object.

After, define the duration spent on the animation, initial and end value of “pos”.

And, start the animation.

By inserting the definition of the series of QPropertyAnimation object “an”
after window.show() of application framework at the first, it is completed.

I’ve prepared here a complete source. Next time, I will describe the fade-in / fade-out of the image.

[Sites Referenced]
Using_Qt_Properties_in_PySide | Qt Wiki | Qt Project

[Related Sites]
junf/PySideSamples · GitHub

[Related Articles]

  1. Display Image While Sliding by Qt | DeVlog – Fly With Your Devil’s Wings –
  2. To Display Images in Full-Screen by PySide | DeVlog – Fly With Your Devil’s Wings –
  3. Fade in / Fade-out Images by PySide | DeVlog – Fly With Your Devil’s Wings –
  4. Realize Zoom-in and Zoom-out the Image in PySide | DeVlog – Fly With Your Devil’s Wings –

To Display Images in Full-Screen by PySide


Introduction

Recently, I started Python programming to make applications on multi-platform. I selected “PySide” as a GUI library, and have been having trial and error in various ways. From those, I would like to post articles as a result of playing my particular interest. This time, I will describe how to display image in the full screen.

In addition, although 2.x mainstream is still Python, because movement to migrate to 3.x is likely to be activated in the future and 3.x is suitable to support Japanese language, I am programming in Python3.3. Therefore, please note the following code does not take into account any operation in 2.x.

Display an Image

First, I’ll try to make a code to display an image in PySide. You will see the JPEG file called “hoge.jpg”.

Read the image by the “QPixmap” object, set it to “QLabel” object by “setPixmap()” and display it by “show()” method. Although you would think that “label” is for displaying “text”, “QLabel” will function as a screen for image and text.

Window appears on the desktop as follows.
normal

Display Image in Full Screen

By changing “show()” to “showFullScreen()” in line 8, you can achieve the full-screen display.

It is displayed in full screen as follows. There is no frame of the window.
full

However, “close button” does not appear in full screen state. You will need to be able to release the full screen by handling the key event. (If you happen to display in full screen without any measures, switch to another task by ALT + TAB, and then you can close the application from the taskbar.)

Get the Key Events of QLabel

“QLabel”, as one of the parts of GUI, is inherit “QWidget”. It has the method “keyPressEvent” to handle the key events.

Define a class called “Screen” that inherits from “QLabel”, then you are going to be able to handle the ESC key to override the “keyPressEvent”.

If you press the ESC key, display is switched in maximum display / full screen. Please note that in order to return to the normal display, you’re calling the “showNormal()”.

By using this “Screen” class instead of QLabel, you will respond to the ESC key.

If you press the ESC key in the state of being full screen display, display change to maximum as shown below. If in this state, you will be able to terminate the program in close button.
max

The way of the adjustment of display position, please refer to the reference of “QLabel”.

In addition, since I have prepared here the complete code. Prepare a “hoge.jpg” and try it.

[Rlated Sites]
junf/PySideSamples · GitHub

[Rlated Articles]

  1. Display Images in Full-Screen by Qt, Multi-Platform GUI Lib | DeVlog – Fly With Your Devil’s Wings –
  2. Behavior of “geometry” Property and “show” Method in PySide | DeVlog – Fly With Your Devil’s Wings –
  3. Display Image While Sliding by PySide | DeVlog – Fly With Your Devil’s Wings –
  4. Fade in / Fade-out Images by PySide | DeVlog – Fly With Your Devil’s Wings –
  5. Realize Zoom-in and Zoom-out the Image in PySide | DeVlog – Fly With Your Devil’s Wings –