开发者

Qt QLayout inside QDesktopWidget

开发者 https://www.devze.com 2023-01-21 04:52 出处:网络
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 he

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开发者_如何学JAVA - 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消