Qt setGeometry:无法设置几何体
Qt setGeometry: Unable to set geometry
为什么?
setGeometry: Unable to set geometry 22x22+320+145 on QWidgetWindow/'WidgetClassWindow'. Resulting geometry: 116x22+320+145 (frame: 8, 30, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 22x22, maximum size: 16777215x16777215).
该项目是:
项目.pro
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = untitled5
TEMPLATE = app
SOURCES += main.cpp
widget.cpp
HEADERS += widget.h
widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
private:
};
#endif // WIDGET_H
小工具.cpp
#include "widget.h"
#include <QVBoxLayout>
Widget::Widget(QWidget *parent) :
QWidget(parent)
{
QVBoxLayout *vLayout = new QVBoxLayout(this);
}
Widget::~Widget()
{
}
main.cpp
#include "widget.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
添加setGeometry(0,0400300(;在Widget构造函数中删除了该问题。但是窗口不会很好地定位在屏幕的中心。
当小部件的大小非常小时,就会发生此警告(至少对我来说是这样(。
为你的小部件设置一个最小尺寸(这样它就会自动定位(,比如:
// Widget constructor
QVBoxLayout* vLayout = new QVBoxLayout();
setLayout(vLayout);
setMinimumSize(200,200);
您还应该将小部件作为QMainWindow
的父级,但仍然可以工作。
尝试使用adjustSize()
看起来有问题:为什么我得到QWindowsWindow::setGeometry:无法用Qt 5.12.0 设置几何警告
可能的解决方案:Qt无法设置几何
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- 在C++/Linux中设置单调时钟的一些技巧
- 如何在选项卡视图Qt中设置一个新项目,并保存以前的项目
- 嵌套在类中时无法设置成员数据
- 无法将结构注册为增强几何体3D点
- 需要帮助设置在C++中使用的Potrace
- 如何在自删除后将对象设置为nullptr
- 将指针设置为"nullptr"并不能防止双重删除?
- 如何在Ubuntu中使用cmake设置qt4
- ld:bind_at_load和-bitcode_bundle(Xcode设置ENABLE_bitcode=YES)不能
- 如何在boost beast http请求中设置http头
- 如何解决gcc编译器优化导致的centos双编译器设置中的分段错误
- 如何将这个C++哈希表转换为动态扩展和收缩,而不是使用硬设置的最大值
- 为什么文件名被设置为一个点,而不是在读取矢量中的文件名时
- 如何在24位SDL_Surface上设置像素的颜色
- std::设置自定义比较器
- 如何设置一个范围来提取我想要获得的信息
- 如何在C/C++中用FD_set Unix设置套接字文件描述符
- 无法在Qt中设置几何体
- Qt setGeometry:无法设置几何体