PDA

View Full Version : inform QWidget that the screen dimensions changed



Dzha
2nd November 2010, 23:32
My platform changes orientation automatically while QWidget instance is running always full screen. When the rotation happens QWidget keeps old dimensions until it is switched forcefully to non-fullscreen mode and back to the full screen mode (where it finally occupies all screen space in new orientation).

Anyone can suggest a way to refresh QWidget's dimensions while leaving it in full screen mode?

Tried and failed to work: repaint(), setGeometry(), showFullscreen().

high_flyer
3rd November 2010, 08:24
What happens if you try resize()?

Dzha
3rd November 2010, 16:59
I think I found the problem, it was an invisible parent widget sitting behind, when I refresh it then everything works ok.

Dzha
4th November 2010, 09:41
Hmm, still I have to get out of full screen mode and then get back in for Qt to pick up changes in screen dimensions. It works, but redrawing looks really ugly with a lot of flashing. Not sure what I can do about it.
Ideas anyone?

wysota
4th November 2010, 10:17
Hard to say without seeing any code.

Dzha
4th November 2010, 11:47
There is a repaint() and paintEvent() pair.The widget is created and running always full screen. When the widget needs an update it calls repaint(), then in paintEvent it regenerates its screen image and paints it using QPainter.

The screen driver is based on QScreen. When the screen becomes landscape it starts reporting new height and width.

So the widget needs to go into a non-fullscreen state (resize itself for example) and the back to fullscreen to see the new width/height of the screen.

If the widget shows an image in portrait, then after changing the orientation of the device to landscape, the image is not shown completely until the resize/fullscreen is done.

wysota
4th November 2010, 12:02
repaint and paintEvent are completely unrelated to the problem. They have nothing to do with dimensions of your window.

Dzha
4th November 2010, 13:42
OK. If the window receives showFullScreen() and it is in full screen it does nothing. It does not check that the screen has been changed. if it is sent resize(0,0) and then showFullScreen() then it occupies the full screen with new width and height.
The code is trivial. Hardware changed in the background, but the changes are not propagated. Do I need to inform some Qt class that the sceen has been transformed? If yes then how?

There are two methods in QScreen: isTransformed() and transformOrientation(). Both overwritten by my driver and return true/rotation corresponding the situation. No avail. I did a search through Qt and could see that those functions don't do much themselves, probably orientated on the transformation derived class functionality.

@wysota: appreciate your answers, thanks.

wysota
4th November 2010, 14:03
OK. If the window receives showFullScreen() and it is in full screen it does nothing. It does not check that the screen has been changed.
The window does not check anything. It's your (or the window manager's) duty to know the screen size has changed.


The code is trivial. Hardware changed in the background, but the changes are not proagated.
Propagated where?

Dzha
4th November 2010, 15:07
The window does not check anything. It's your (or the window manager's) duty to know the screen size has changed.
OK. Is there a mechanism for informing the windows manager that the screen is changed?

wysota
4th November 2010, 15:10
You can start by reading what a window manager is.

Dzha
4th November 2010, 15:36
Well, all I was able to find while reading the window manager documentation was related to resizing the window, which I want to avoid.
I can not see any method of not leaving the full screen mode (thus avoiding additional repaint) that is described in Qt doc.

If you are aware of it, please tell me.

wysota
4th November 2010, 15:37
Well, all I was able to find while reading the window manager documentation
Which window manager documentation was that?

Dzha
4th November 2010, 15:47
QWS, Qt for Embedded Linux.

wysota
4th November 2010, 16:11
Are you using QWS?

Dzha
4th November 2010, 16:40
Yes, my main app acts as a QWS server. loads a screen plugin and uses it.

wysota
4th November 2010, 17:06
If your application is full screen, what do you need QWS for?

Dzha
4th November 2010, 17:07
QWS also handles dialogs, input, etc.
My main window is an instance of QMainWindow .

wysota
4th November 2010, 19:47
So how do you implement screen geometry change?

Dzha
5th November 2010, 12:09
So how do you implement screen geometry change?

Right, the orientation is implemented in the hardware. The app commands the driver to rotate, the driver changes how pixels are written to the screen and changes what geometry (w,h) is reported to the screen driver plugin. As a result, the dimensions of the screen are different, but the full screen window does not pick them up until it re-enters the full screen mode.
So only the refresh of the screen width and height is required.