Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How to set the style (for instance Material) for QtQuick QML PySide2 app?
Forum Updated to NodeBB v4.3 + New Features

How to set the style (for instance Material) for QtQuick QML PySide2 app?

Scheduled Pinned Locked Moved Solved Qt for Python
3 Posts 2 Posters 2.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rafaldc
    wrote on last edited by rafaldc
    #1

    Hello,

    I am trying an example of use Material style: https://doc.qt.io/qt-5/qtquickcontrols2-material.html but it renders without colors nor Material style at all:

    0_1551653118562_90a204c2-b263-4869-b229-78d44746b315-image.png

    I believe I should use QQuickStyle.setStyle method which is not available in PySide2? https://doc.qt.io/qt-5/qquickstyle.html

    My example code:

    import QtQuick 2.12
    import QtQuick.Controls 2.12
    import QtQuick.Controls.Material 2.12
    
    ApplicationWindow {
        visible: true
        Column {
            anchors.centerIn: parent
            RadioButton { text: qsTr("Small") }
            RadioButton { text: qsTr("Medium");  checked: true }
            RadioButton { text: qsTr("Large") }
    		Button {
    		    text: qsTr("Button")
    		    highlighted: true
    		    Material.background: Material.Red
    		}
    	    Pane {
    		    width: 120
    	    	height: 120
    	    	Material.elevation: 6	
    		    Label {
    	    	    text: qsTr("I'm a card!")
    	        	anchors.centerIn: parent
    	    	}
    		}
    	}
    }
    
    from PySide2.QtWidgets import QApplication
    from PySide2.QtQuick import QQuickView
    from PySide2.QtCore import QUrl
    
    app = QApplication([])
    view = QQuickView()
    url = QUrl("view.qml")
    
    view.setSource(url)
    view.show()
    app.exec_()
    
    

    What is a correct way to set a style?

    1 Reply Last reply
    0
    • CristianMaureiraC Offline
      CristianMaureiraC Offline
      CristianMaureira
      wrote on last edited by
      #2

      You need to pass --style material to the command line and handle that as an argument of your QApplication. Another option is to do this from the code itself using the approach from this example

      sys.argv += ['--style', 'material']
      app = QGuiApplication(sys.argv)
      
      1 Reply Last reply
      4
      • R Offline
        R Offline
        rafaldc
        wrote on last edited by
        #3

        Thanks, it works!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved