English 中文(简体)
Qt Q桌面小工具内部的布局
原标题:Qt QLayout inside QDesktopWidget
  • 时间:2010-10-20 21:59:35
  •  标签:
  • qt
  • layout

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)

我的想法是使用QDesktopWidget作为基本的小部件,将stratch项放入我的QLayout中(将内部(我的)小部件左右对齐)

我的代码原型在这里:

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);

但它不起作用。。。

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 ;-) )

附言:在其他小部件中使用qlayout的想法是有效的,例如在视图的certer处使用带有沙时钟的QTextBrowser等。

问题回答

QDesktopWidget不打算像典型的小部件一样使用(至少据我所知,我很惊讶文档中没有更明确地说明这一点)。因此,您不应该尝试为其设置小部件的父级或尝试为其分配布局。您调用它的方法来获取有关桌面环境的信息,或连接到它的信号以了解更改。

使用这些信息,您可以设置自己的应用程序小部件的几何图形,以便它们显示在您想要的正确屏幕和位置上。

此页面显示了一些基本功能。





相关问题
Very basic WPF layout question

How do I get this listbox to be maxiumum size, i.e. fill the group box its in. I ve tried width="auto" Height="auto", width="stretch" Height="stretch" annoyingly at the moment, it dynamicly sizes to ...

How to align the text to top of TextView?

How to align the text to top of a TextView? Equivalent Android API for Swings setInsets()? that is top of text should start be in (0,0) of TextView <?xml version="1.0" encoding="utf-8"?> <...

Centring a flow in Shoes

Can I center the contents of a flow in Shoes? I know that a paragraph can be centred like: para Centred paragrpah , :align=> center However, this does not work with flows: flow(:align=> ...

Overlaying with CSS

I want to load a website in an iframe, and overlay the website with some hints about the website that is shown. However, i got stuck at the point that the website has a variable passive white space at ...

How do you normally make a program look beautiful? [closed]

How can I make an Application look nice and not like an amateur pulled it together? I mean graphic-wise. Is there some sort of book you can read regarding beautiful program layouts, etc? I put this ...

热门标签