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. Easy question...How to use setProperty to set text alignment?

Easy question...How to use setProperty to set text alignment?

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

    I have this in my code:
    QObject *pObject = pRootObject->findChild<QObject *>("MyTextItem");
    pObject->setProperty("horizontalAlignment", "Text.AlignLeft");

    But when I execute the code, the qml text does not change alignment from Center to Left

    QML has this:
    Text {
    id: primaryText1
    objectName: "MyTextItem"
    x: 8
    y: 5
    width: 309
    height: 25
    text: qsTr("Hello!")
    horizontalAlignment: Text.AlignHCenter
    }

    any ideas? Thanks!

    1 Reply Last reply
    0
    • DiracsbracketD Offline
      DiracsbracketD Offline
      Diracsbracket
      wrote on last edited by Diracsbracket
      #2

      @WalterWhite
      Use this:

      pObject->setProperty("horizontalAlignment", Qt::AlignLeft);
      
      1 Reply Last reply
      2
      • WalterWhiteW Offline
        WalterWhiteW Offline
        WalterWhite
        wrote on last edited by
        #3

        @Diracsbracket said in Easy question...How to use setProperty to set text alignment?:

        Qt::AlignLeft

        well if that isn't a duh moment.
        yup. that was it. :)
        I figured since "true" or "false" works, why shouldn't the text form of alignment.

        Thank you!

        1 Reply Last reply
        1

        • Login

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