gpt4 book ai didi

c++ - doLayout : how to setGeometry on top of another widget?

转载 作者:行者123 更新时间:2023-11-28 02:15:24 25 4
gpt4 key购买 nike

我想在这里创建类似的自定义布局:http://doc.qt.io/qt-5/qtwidgets-layouts-flowlayout-flowlayout-cpp.html

我想要一些方法将复选框放在自定义按钮的顶部。目前有

setGeometry(QRect(QPoint(...

按钮和复选框的方法,但无论我是先为按钮还是复选框做这件事,复选框仍然出现在按钮“下方”,我看不到/点击它。

我怎样才能把复选框放在按钮上面?

最佳答案

只需将复选框设为按钮的子项,并调用与按钮相关的 setGeometry。 child 总是被吸引到 parent 之上。

QPushButton button("Hello World!", &w);
button.setGeometry(0,0,100,100);
button.show();

QCheckBox checkBox(&button);
checkBox.setGeometry(button.rect());
checkBox.show();

无需将复选框放入布局中。

关于c++ - doLayout : how to setGeometry on top of another widget?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34173778/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com