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. Custom style isn't applied

Custom style isn't applied

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qmlqtcreatorstylingcustom style
1 Posts 1 Posters 524 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
    Rivvil
    wrote on last edited by Rivvil
    #1

    Hello. I've read about Creating a Custom Style and about Using Styles in Qt Quick Controls. Also, I've used this Flat Style example as practical example of how and what to do.

    So, seems like I've done everything according to the official documentation, but unfortunately I'm not able to make my application to use the custom style I've created. Maybe I end up doing something wrong or misunderstood something? Could you, please, take a look?

    My custom style MyStyle consists of a single file Text.qml (just for a testing purposes for now):

    import QtQuick.Templates 2.15 as T
    
    T.Text {
      font.pointSize: 32
      color: "white"
    }
    

    QtCreator doesn't like this code for some reason:
    Screenshot_2.png
    I also tried to add "import QtQuick 2.15" line, it doesn't change anything.

    MyStyle directory is in the project root. Text.qml is in a resource file qml.qrc (which contains other .qml project files):
    Screenshot_3.png
    I've tried two different approaches to using the style. First, adding qtquickcontrols2.conf file (into qml.qrc) with the following content:

    [Controls]
    Style=MyStyle
    

    Second, using setStyle call before loading main window component via QQmlApplicationEngine:

    QQuickStyle::setStyle(":/MyStyle");
    

    Neither of these two works. Building and running the project doesn't give any errors. So, I can't understand what the problem is. The style just isn't applied - Text component doesn't use my font size and color.

    My version of Qt is 5.15.1 (mingw 8.1 32bit). and QtCreator is:
    Qt Creator 4.13.2
    Based on Qt 5.15.1 (MSVC 2019, 64 bit)
    Built on Oct 1 2020 01:14:56

    Thank you in advance.

    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