为什么?
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).
Run Code Online (Sandbox Code Playgroud)
该项目是:
project.pro
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = untitled5
TEMPLATE = app
SOURCES += main.cpp\
widget.cpp
HEADERS += widget.h
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
widget.cpp
#include "widget.h"
#include <QVBoxLayout>
Widget::Widget(QWidget *parent) :
QWidget(parent)
{
QVBoxLayout *vLayout = new QVBoxLayout(this);
}
Widget::~Widget()
{
}
Run Code Online (Sandbox Code Playgroud)
main.cpp中
#include "widget.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
Run Code Online (Sandbox Code Playgroud)
添加setGeometry(0,0,400,300); 在Widget构造函数中删除该问题.但是窗口不会精美地定位在屏幕的中央.
Mik*_*iki 19
当窗口小部件的大小非常小时,会发生此警告(至少对我而言).
设置窗口小部件的最小大小(因此它将自动定位),如:
// Widget constructor
QVBoxLayout* vLayout = new QVBoxLayout();
setLayout(vLayout);
setMinimumSize(200,200);
Run Code Online (Sandbox Code Playgroud)
您还应该将您的小部件设为父级QMainWindow,但仍然有效.
| 归档时间: |
|
| 查看次数: |
17887 次 |
| 最近记录: |