前言
好久没用过Qt location map了,最近又开始在使用了,说下Qt location 的现状,因Qt6不支持Qtlocation,所在我用的Qt版本还在qt5.但是迁移Qt6的工作正在进行中,现在虽然还没有加入到正式版本中,但是也可以自己在Qt6中编译使用https://bugreports.qt.io/browse/QTBUG-96795
Qt location 中的抗锯齿
在map中绘制线的时候,会发现锯齿比较严重,查看Qt官方的手册中看到有一种使用方式:
// The code below enables SSAA
layer.enabled: true
layer.smooth: true
property int w : width
property int h : height
property int pr: Screen.devicePixelRatio
layer.textureSize: Qt.size(w * 2 * pr, h * 2 * pr)
https://doc.qt.io/qt-5/location-plugin-itemsoverlay.html
但此方式不启作用
最后有找到另外的解决方式:https://stackoverflow.com/a/49576756
直接在map中添加如下代码即可
Map{
layer.enabled: true
layer.samples: 8
/// 其它添加进map的控件
...
}
也可以全局使用
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QSurfaceFormat format;
format.setSamples(8);
QSurfaceFormat::setDefaultFormat(format);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec();
}
在QML中添加可以对单个控件使用,main中设置是全局设置,二者选一个就可以了,建议只在QML中设置即可。