2应用程序中的非本机对话框

2应用程序中的非本机对话框

本文介绍了Qt Quick 2应用程序中的非本机对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从导入QtQuick.Dialogs 创建非本地,非 QDialog 派生的对话框( QFileDialog 等)?

How to make dialogs from import QtQuick.Dialogs to be non-native, non-QDialog-derived (QFileDialog etc)?

可以制作 QFileDialog 设为非本地()。但是如何在 QML 中制作对话框以在 xcb QPA和 eglfs QPA上呈现

It is possible to make QFileDialog to be non-native (QFileDialog::Option::DontUseNativeDialog). But how to make dialogs in QML to be rendered on xcb QPA and on eglfs QPA in the similar way?

推荐答案

更改此内容

QApplication app(argc, argv);

对此

QGuiApplication app(argc, argv);

Dialog 的窍门,但不是 FileDialog 。实际上,它告诉 QtQuick.Dialogs 您没有使用窗口小部件,但也会影响所使用的样式。

does the trick for Dialog, but not FileDialog. It essentially tells QtQuick.Dialogs that you're not using widgets, but it also affects the style that is used.

检查使用哪个应用程序的代码是:

The code that checks which application is in use is here:

static QString defaultStyleName()
{
    //Only enable QStyle support when we are using QApplication
#if defined(QT_WIDGETS_LIB) && !defined(Q_OS_IOS) && !defined(Q_OS_ANDROID) && !defined(Q_OS_BLACKBERRY) && !defined(Q_OS_QNX) && !defined(Q_OS_WINRT)
    if (QCoreApplication::instance()->inherits("QApplication"))
        return QLatin1String("Desktop");
#elif defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED)
    if (QtAndroidPrivate::androidSdkVersion() >= 11)
        return QLatin1String("Android");
#elif defined(Q_OS_IOS)
    return QLatin1String("iOS");
#elif defined(Q_OS_WINRT) && 0 // Enable once style is ready
    return QLatin1String("WinRT");
#endif
    return QLatin1String("Base");
}

解释了该过程:

For FileDialog, there is this paragraph that explains the process:

这篇关于Qt Quick 2应用程序中的非本机对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 01:34