View Full Version : Qwidget Show abnormal /setGeometry not working

28th April 2013, 12:17
I build a app use QtCreator /MSVC2010 (Win7 )

my app UI extend QWidget,the geometry is (0,0,860,600)

Where i run it on windows xp sp3(only one system is abnormal,anothers is good) , the app show abnormal,show a big big window.

I'm Rewrite the QWidget::resizeEvent(e){
} function,print the size and oldsize information:

i print :

old size -1,-1, new size > 3766,600

but on my PC,the UI show normal,

old size -1,-1, new size > 860,600

then ,i write these code :

if(oldWin.width() == -1 &&
oldWin.height() == -1){
if(size.width() != 860 || size.height() != 600){

in resizeEvent(e);
and the resize and setGeometry do not work ,the window still show abnormal~

who can tell me ? Why ?

28th April 2013, 14:42
Don't you think that it never enters the condition ? why would it ever be necessary to check width and height with -1 ?

(insert your code between
tags. and don't mix code with statements)

28th April 2013, 19:32
Maybe you should read the documentation for QWidget::geometry(), especially this part:

Warning: Calling setGeometry() inside resizeEvent() or moveEvent() can lead to infinite recursion.

See the Window Geometry documentation for an overview of geometry issues with windows.

2nd May 2013, 04:20
thanks for your reply,

my problem is qwidget show abnormal ,at begin, my widget geometry is 0,0,860,600, but it's display an 0,0,3766,600 window. my layout is HorizontalLayout

2nd May 2013, 07:26
If you use layouts then calling setGeometry is a no-op as the layout will override it.