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. text positioning/wrap conflict
Forum Updated to NodeBB v4.3 + New Features

text positioning/wrap conflict

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

    Hi all -

    I've run into something that appears to be a Catch-22 with text formatting.

    Rectangle {
      height: root.highlightedBarHeight_
      width: root.highlightedBarWidth_ * 3
      radius: root.highlightedBarWidth_ / 10
      Text {
        anchors {
          horizontalCenter: parent.horizontalCenter
          verticalCenter: parent.verticalCenter
        }
        text: "remove cap"
        width: parent.width // need this to make wrapping work.
        wrapMode: Text.WordWrap
      }
    }
    

    The above code will not center the text in the rectangle, despite the anchors. I traced the problem to the presence of the width: line. BUT: if I remove the width line, wrapMode won't work, so the text can run off the side of the rectangle.

    I'm sure I'm not the first person to run across this, but...how does one go about getting centering and wrapping in the same element?

    Thanks...

    J.HilkJ 1 Reply Last reply
    0
    • mzimmersM mzimmers

      Hi all -

      I've run into something that appears to be a Catch-22 with text formatting.

      Rectangle {
        height: root.highlightedBarHeight_
        width: root.highlightedBarWidth_ * 3
        radius: root.highlightedBarWidth_ / 10
        Text {
          anchors {
            horizontalCenter: parent.horizontalCenter
            verticalCenter: parent.verticalCenter
          }
          text: "remove cap"
          width: parent.width // need this to make wrapping work.
          wrapMode: Text.WordWrap
        }
      }
      

      The above code will not center the text in the rectangle, despite the anchors. I traced the problem to the presence of the width: line. BUT: if I remove the width line, wrapMode won't work, so the text can run off the side of the rectangle.

      I'm sure I'm not the first person to run across this, but...how does one go about getting centering and wrapping in the same element?

      Thanks...

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @mzimmers

      Text {
          anchors {
            horizontalCenter: parent.horizontalCenter
            verticalCenter: parent.verticalCenter
          }
          text: "remove cap"
          horizontalAlignment: Text.AlignHCenter
          verticalAlignment: Text.AlignVCenter
          width: parent.width // need this to make wrapping work.
          wrapMode: Text.WordWrap
        }
      

      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      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