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. Protoyping custom qtquickcontrols2 styles with qmlscene
QtWS25 Last Chance

Protoyping custom qtquickcontrols2 styles with qmlscene

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 3 Posters 500 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.
  • F Offline
    F Offline
    fulekia
    wrote on last edited by
    #1

    I've found a few posts and bugs about loading the stock styles with qmlscene (e.g., Material), but not custom styles, and I can't seem to figure it out. I created a myTheme sub folder, copied in the default quick controls Button.qml template, and changed some things (background color, radius, etc.). Now how do I get qmlscene to load that? Neither QT_QUICK_CONTROLS_STYLE=myTheme nor -style myTheme work (by name, relative path, or absolute path).

    I created a test.qml file with a Dialog component + OK/Cancel buttons, and the buttons still have the default look, and not the modified background from ./myTheme/Button.qml.

    How do you do this? Setting the style to Material clearly changes the Dialog buttons.

    1 Reply Last reply
    0
    • MarkkyboyM Offline
      MarkkyboyM Offline
      Markkyboy
      wrote on last edited by
      #2

      You need to add a 'qtquickcontrols2.conf' file to your project and populate it;

      https://doc.qt.io/qt-5/qtquickcontrols2-configuration.html

      qtquickcontrols2conf.JPG

      Don't just sit there standing around, pick up a shovel and sweep up!

      I live by the sea, not in it.

      F 1 Reply Last reply
      0
      • MarkkyboyM Markkyboy

        You need to add a 'qtquickcontrols2.conf' file to your project and populate it;

        https://doc.qt.io/qt-5/qtquickcontrols2-configuration.html

        qtquickcontrols2conf.JPG

        F Offline
        F Offline
        fulekia
        wrote on last edited by
        #3

        @Markkyboy ah, I’m just running qmlscene directly, and not in a project. I have several very complicated projects, and I was hoping to do rapid prototyping with less project overhead. Will that just not work? I suppose making a project shell isn’t that much work, I just didn’t know if qmlscene was aware of the resource system.

        Interestingly, if I do this:
        QT_QUICK_CONTROLS_STYLE=./myTheme qmlscene main.qml

        Then buttons used directly in main show the rounded corners of my sample style, but the buttons in the Dialog do not. So it can clearly find the style, it just doesn’t use it everywhere? I thought maybe there was a name conflict, but namespacing/aliasing the quick controls import didn’t help.

        1 Reply Last reply
        0
        • F Offline
          F Offline
          fulekia
          wrote on last edited by fulekia
          #4

          Creating a full project doesn't work either. I used Qt Creator to make a basic Qt Quick app (Stack view with Material style), added a MyStyle sub directory with my styled Button.qml to qml.qrc, updated qtquickcontrols2.conf to say Style=MyStyle, and I get the same result:
          bad-dialog-buttons.png

          You can see that the "Wuzzup" button is rounded and blue, but the Dialog buttons are not.

          Am I missing some fundamental conceptual piece for how controls styling works? Do I have to rebuild dialogs from scratch? That can't be right, otherwise custom styles just end up being complete re-implementations.

          1 Reply Last reply
          0
          • F Offline
            F Offline
            fulekia
            wrote on last edited by
            #5

            So, I don't know that I'd call this a solution, but I'm leaving a note here for future reference. I needed to add a DialogButtonBox.qml to my custom style to make the button styles apply to Dialogs. Just copy-pasting the default template from the Quick Controls source without changes was sufficient.

            I suppose this means that making a custom Quick Controls 2 style really means implementing the whole enchilada; you need to define every component in the chain, which in my case means forking and maintaining everything. That's a lot more work than I'd hoped for, but I suppose that's how this particular cookie crumbles.

            1 Reply Last reply
            0
            • Z Offline
              Z Offline
              Zuuka
              wrote on last edited by
              #6

              As far as i know, the controls defined in the style need to inherit from Template classes (e.g. T.Dialog {...}).

              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