tags:

views:

21

answers:

1

I want to do universal method to set position of my widget. All I wanna get it is set right coordinates for my widget wich must always be in right bottom corner of desktop. My widget can change his height (or maybe width) but it must have adjusted size by both ordinates... (too many words)

My idea is using QDesktopWidget as basic widget to put into my QLayout with stratch items (to align inner (my) widget to right and to bottom sides)

my code prototype is here:

QDesktopWidget * desktopWidget = QApplication::desktop();
MyWidget * myWidget = new MyWidget(desktopWidget);
QVBoxLayout * vlayout = new QVBoxLayout;
vlayout->addStretch();
vlayout->addWidget(myWidget);
QHBoxLayout * hlayout = new QHBoxLayout(desktopWidget);
hlayout->addStretch();
hlayout->addLayout(vlayout);

but it doesn't work...

Help me please implement my idea if you know how. At this moment I know only one work way to do it - it is manually set pos of widget and handle many events (resize etc.) - but this is not good... (because i do it bad of cause ;-) )

PS: idea with qlayout inside other widget is working for example with QTextBrowser with sandclock at certer of view, etc.

+1  A: 

A QDesktopWidget isn't intended to be used like a typical widget (at least as far as I'm aware, I'm surprised the documentation isn't more explicit about that). So you shouldn't try to parent widgets to it or try to assign it a layout. You call its methods to obtain information about the desktop environment or connect to its signals to be informed of changes.

Using this information, you would then set the geometry of your own application widgets so that they appear on the correct screen and position you want.

This page shows some basic functionality.

Arnold Spence
I see. That is why i ask how to do it in the best way. Do you have idea?
vinnitu