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. How to apply my own custom styling to text elements?
Qt 6.11 is out! See what's new in the release blog

How to apply my own custom styling to text elements?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 2 Posters 880 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.
  • J Offline
    J Offline
    JesperBorri
    wrote on last edited by
    #1

    I have the following code:

    Text {
        id: tid
        text: qsTr("Tid")
    
        width: parent.width           //this is the part i want to style on every headline element
        verticalAlignment: Text.AlignVCenter
        horizontalAlignment: Text.AlignHCenter
        Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
        font.pixelSize: 24
    }
    

    I want to repeat all of the code and use on other element like

    Text {
          id: tid2
          text: qsTr("tid2")
          
           (some kind of headline styling)
    }
    

    How do i make a some kind of style, that i can use repeatly on every headline element?

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @JesperBorri Custom reusable components are quite easy to make. Just add your stylized Text code inside a separate QML file say for eg. MyText.qml. So now whenever you want to use this stylied custom component is another qml code, just import this file and load MyText component inside it. All your information is contained inside this loaded component. That's it.

      157

      1 Reply Last reply
      3

      • Login

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