的图象比语言更好(在红色 ApplicationWindow 黑色矩形):矩形不覆盖整个ApplicationWindow
通知在顶部和右侧的红色未填充区域。右侧的红色可能很难注意到,但它在那里!我想这是我在黑有彩色填充整个应用程序窗口的矩形。看到代码:
main.qml
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
ApplicationWindow {
id: window
visible: true
/* Developing mobile apps you don’t need to set width
and height, because the ApplicationWindow always grabs
the total available space.
*/
//width: 640
//height: 480
color: "#ff0000" // Red color
/* For some reasons i want this Rectangle here
* and it MUST fill the entire window but I notice
* a pixel or two line on top and right of the
* screen.
*/
Rectangle {
id: page
width: window.width; height: window.height
//anchors.fill: parent // same output
color: "#000000" // Black color
}
}
的main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QLatin1String("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec();
}
我不知道我在这里失踪:(
请分享解决方案/解决此问题的
我也试过,但还是一样的输出。
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import QtQuick.Window 2.2
Window {
id: window
visible: true
height: Screen.height
width: Screen.width
/* Developing mobile apps you don’t need to set width
and height, because the ApplicationWindow always grabs
the total available space.
*/
//width: 640
//height: 480
color: "#ff0000" // Red color
/* For some reasons i want this Rectangle here
* and it MUST fill the entire window but I notice
* a pixel or two line on top and right of the
* screen.
*/
Rectangle {
id: page
width: window.width; height: window.height
//anchors.fill: parent // same output
color: "#000000" // Black color
}
}
我注意到,在main.cpp中的以下行注释解决了问题,但现在所有的小部件,我想在UI中显示看起来真的很小..!他们在小屏幕设备,而小大屏幕的设备看起来很好。 :(
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
这个任何解决方案
编辑:?! 这是已报道HERE因为几乎一年一个如果你正面临着同样的问题一个确认的错误,那么请登录https://bugreports.qt.io/和投票THIS错误。
也许是因为ApplicationWindow后不抓住所有内容?你可以试着用'import QtQuick.Window 2.2'来显式设置宽度和高度:'height:Screen.height'和'width:Screen.width'。 – sk2212
@ sk2212我试过了,但没有奏效。我编辑了我的问题以包含您的建议。 –
@ sk2212我们走吧!我注意到,如果我评论 QCoreApplication :: setAttribute(Qt :: AA_EnableHighDpiScaling); 然后矩形按预期填充整个窗口,但现在UI小部件看起来很小。 –