Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Defining Qt Quick Controls Styles as a seperate stylesheet
Qt 6.11 is out! See what's new in the release blog

Defining Qt Quick Controls Styles as a seperate stylesheet

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 2 Posters 5.4k Views 1 Watching
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hi all,

    Is there any way we can define the "Qt Quick Controls Styles (http://qt-project.org/doc/qt-5.1/qtquickcontrolsstyles/qtquickcontrolsstyles-index.html), as a new stylesheet (for example, style.qml) and
    use this stylesheet(style.qml) in other QML files.

    Best Regards,
    Ansif

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      Hi,

      the answer is YES; you can define custom styles as Components and use them like other custom components.

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        [quote author="mcosta" date="1385569765"]Hi,

        the answer is YES; you can define custom styles as Components and use them like other custom components.[/quote]

        Thank you for your reply. Can you show me a small example.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mcosta
          wrote on last edited by
          #4

          Hi,

          simply you have to:

          create a QML file for each style (MyButtonStyle, MySliderStyle, ....)

          for each control you set the style Property

          example
          @
          // File: MyButtonStyle.qml

          import QtQuick 2.1
          import QtQuick.Controls.Styles 1.0

          ButtonStyle {
          ....
          }
          @

          @
          // File: main.qml

          import QtQuick 2.1
          import QtQuick.Controls 1.0

          Rectangle {

          Column {

          Button {
            id: button1
            ...
            style: MyButtonStyle {}
          }
          
          Button {
            id: button2
            ...
            style: MyButtonStyle {}
          }
          

          }
          @

          Once your problem is solved don't forget to:

          • Mark the thread as SOLVED using the Topic Tool menu
          • Vote up the answer(s) that helped you to solve the issue

          You can embed images using (http://imgur.com/) or (http://postimage.org/)

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            [quote author="mcosta" date="1385650066"]Hi,

            simply you have to:

            create a QML file for each style (MyButtonStyle, MySliderStyle, ....)

            for each control you set the style Property

            example
            @
            // File: MyButtonStyle.qml

            import QtQuick 2.1
            import QtQuick.Controls.Styles 1.0

            ButtonStyle {
            ....
            }
            @

            @
            // File: main.qml

            import QtQuick 2.1
            import QtQuick.Controls 1.0

            Rectangle {

            Column {

            Button {
              id: button1
              ...
              style: MyButtonStyle {}
            }
            
            Button {
              id: button2
              ...
              style: MyButtonStyle {}
            }
            

            }
            @[/quote]

            Hi,

            Great.. Thanks for your help. Actually i was looking for a common file (example: style.qml ) which can include the whole styles like Buttonstyle, Editbox style, RadioButton style and so on. By importing the style.qml, we
            can use the individual styles for each controls.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mcosta
              wrote on last edited by
              #6

              Hi,

              you can't use a single file for all styles; you need a file for Component (Style).

              Also you can read "here":http://qt-project.org/doc/qt-5.1/qtqml/qtqml-modules-topic.html to learn how to create a QML Module

              Once your problem is solved don't forget to:

              • Mark the thread as SOLVED using the Topic Tool menu
              • Vote up the answer(s) that helped you to solve the issue

              You can embed images using (http://imgur.com/) or (http://postimage.org/)

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #7

                [quote author="mcosta" date="1385715893"]Hi,

                you can't use a single file for all styles; you need a file for Component (Style).

                Also you can read "here":http://qt-project.org/doc/qt-5.1/qtqml/qtqml-modules-topic.html to learn how to create a QML Module[/quote]

                Hi,

                I have checked the QML module technique. Its a good idea to use the qmldir to include all styles in a single module.

                Thank you for your help..

                Best Regards
                Ansif

                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