2017-07-26 46 views

回答

2

更改此

QApplication app(argc, argv); 

这个

QGuiApplication app(argc, argv); 

的伎俩为Dialog,但不FileDialog。它基本上告诉QtQuick.Dialogs你没有使用小部件,但它也会影响使用的样式。

,检查该代码的应用程序正在使用中是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"); 
} 

void QQuickAbstractDialog::setVisible(bool))似乎控制哪个对话的类型被示出。我不知道是否有一种方法使用公共QML API迫使非本地对话框,但你总是可以修补的Qt:

diff --git a/src/dialogs/qquickabstractdialog.cpp b/src/dialogs/qquickabstractdialog.cpp 
index ce87d56..416f796 100644 
--- a/src/dialogs/qquickabstractdialog.cpp 
+++ b/src/dialogs/qquickabstractdialog.cpp 
@@ -81,7 +81,7 @@ void QQuickAbstractDialog::setVisible(bool v) 
    if (m_visible == v) return; 
    m_visible = v; 

- if (m_dialogHelperInUse || v) { 
+ if (0 /*m_dialogHelperInUse || v*/) { 
     // To show the dialog, we first check if there is a dialog helper that can be used 
     // and that show succeeds given the current configuration. Otherwise we fall back 
     // to use the pure QML version. 

仅此补丁是足以迫使使用的QML对话框实现。

对于FileDialog,有this paragraph解释的过程:

的FileDialog的实施将是一个平台的文件对话框,如果 可能。如果这是不可能的,那么它会尝试实例化一个QFileDialog。如果这也是不可能的,那么它将回退到QML实现 ,DefaultFileDialog.qml。在这种情况下,你可以通过编辑这个文件来自定义外观 。 DefaultFileDialog.qml 包含一个Rectangle来保存对话框的内容,因为某些 嵌入式系统不支持多个顶层窗口。当 对话框变得可见时,如果可能的话,它将自动被包装在窗口 中,或者如果 只能是一个窗口,则主窗口顶部将被重新包装。

+0

我需要最新的回退。 – Orient

+0

我不能直接使用'DefaultFileDialog'。 'QGuiApplication'什么都不做。 – Orient

+0

“最新的回退”? – Mitch

相关问题