2016-11-05 34 views
0

我正在使用Qt 5.7。我的操作系統是Ubuntu 16.04。我的基本代碼是在這裏:Qt:Material Design未運行

import QtQuick 2.7 
import QtQuick.Controls 2.0 
import QtQuick.Layouts 1.0 

import QtQuick.Controls.Material 2.0 

ApplicationWindow { 
    visible: true 
    width: 300 
    height: 300 
    title: qsTr("Hello World") 

    Material.theme: Material.Dark 
    Material.accent: Material.Green 

    Column { 
    anchors.centerIn: parent 

    RadioButton { text: qsTr("Radio Button 1") } 
    RadioButton { text: qsTr("Radio Button 2") } 
    RadioButton { text: qsTr("Radio Button 3") } 
    } 
} 

我用料設計,但是當我跑在桌面上這個程序,我看到Qt的默認樣式,而不是材料設計:Image Link。我沒有收到任何錯誤或警告。當我在Android設備(平板電腦)和Genymotion上運行此應用程序時,我看到了相同的結果。我正在使用NVIDIA卡,我的驅動程序是X.Org(開源)。但是當我使用NVIDIA 340.98驅動程序時,我收到了這個警告:"NV-GLX" missing on display ":0",我發現這款應用程序的風格不是桌面,Android設備或Genymotion上的材質設計。我怎麼解決這個問題?我如何在Qt/QML上使用材料設計?

回答

1

導入樣式併爲其設置屬性不會使應用程序以該樣式運行。您可以在同一個文件中導入多個樣式,爲每個樣式設置特定於樣式的屬性。這些應用程序以特定樣式運行時會生效。請參閱Using Styles in Qt Quick Controls 2瞭解可用於選擇特定樣式的方法。

+0

謝謝,我用[qputenv](http://doc.qt.io/qt-5/qtglobal.html#qputenv):'qputenv(「QT_QUICK_CONTROLS_STYLE」,「material」);'' –