We have moved to a new Sailfish OS Forum. Please start new discussions there.
1

Text.RichText - problem in landscape on tablet. Need help. [answered]

asked 2016-09-03 16:54:11 +0300

Schturman gravatar image

updated 2016-09-03 20:25:28 +0300

Hi
Can someone help me to fix my problem with RichText ? I've added a link in the Label by using textFormat: Text.RichText and everything works, but on a tablet in a landscape mode, for some reasons width of text defines the screen as a portrait mode and the right side of screen have a lot of free space (see picture).
Text.RichText_image
If I remove the textFormat: Text.RichText line, the link stops to be link and shown as a plain text.
Here is a block of Label:

Label {
    text: "* Many custom icons you can find <style>a:link{color: " + Theme.highlightColor + ";}</style><a href=\"http://talk.maemo.org/showthread.php?t=92073\">here</a>.<br>* Put your custom icons (.png format ONLY) to: \"/home/nemo/Pictures/.jolla_android_icons\".<br>* Rename your icons with any file manager."
    font.pixelSize: Theme.fontSizeMedium
    x: Theme.paddingLarge
    width: parent.width - Theme.paddingLarge * 2
    horizontalAlignment: Text.AlignHLeft
    wrapMode: Text.WordWrap
    textFormat: Text.RichText
    onLinkActivated: {
         Qt.openUrlExternally(link)
        }
   }

Here is a full file: http://pastebin.com/efv6tk6R

What I have already tried:
1. Removing textFormat: Text.RichText - link stops to be link
2. Removing wrapMode line - text going over the screen
3. Changing Text.WordWrap to Text.Wrap and Text.WrapAnywhere - nothing changed, the width of text in landscape still shown like in portrait mode.
4. Removing <style>a:link{color: " + Theme.highlightColor + ";}</style> - changed only color of link (dark blue instead from theme) and the width of text in landscape still shown like in portrait mode.
5. Tried to play with parent.width - no needed result...

Please, can someone help me to fix it ?
Thanks

EDIT:
Thanks to @otsaloma for answer, it should looks like this:

Label {
    id: label
    text: "* Many custom icons you can find <style>a:link{color: " + Theme.highlightColor + ";}</style><a href=\"http://talk.maemo.org/showthread.php?t=92073\">here</a>.<br>* Put your custom icons (.png format ONLY) to: \"/home/nemo/Pictures/.jolla_android_icons\".<br>* Rename your icons with any file manager."
    font.pixelSize: Theme.fontSizeMedium
    x: Theme.paddingLarge
    width: parent.width - Theme.paddingLarge * 2
    horizontalAlignment: Text.AlignHLeft
    wrapMode: Text.WordWrap
    textFormat: Text.RichText
    onWidthChanged: label.doLayout();
    onLinkActivated: {
         Qt.openUrlExternally(link)
        }
   }

Now all work correctly in both modes (portrait and landscape).

edit retag flag offensive reopen delete

The question has been closed for the following reason "the question is answered, an answer was accepted" by Schturman
close date 2016-09-03 20:19:43.365857

1 Answer

Sort by » oldest newest most voted
1

answered 2016-09-03 19:42:34 +0300

Maybe you need to call Text.doLayout ? e.g.

Label {
    id: label
    ...
    onWidthChanged: label.doLayout();
}

In my experience this is sometimes needed, but I don't know when exactly.

edit flag offensive delete publish link more

Comments

Wow!!! it exactly what needed !!! All fixed now, thank you very much !
Probably if textFormat: Text.RichText used, width need it to work correctly in both modes (portrait and landscape).
Problem solved! :D

Schturman ( 2016-09-03 20:18:46 +0300 )edit

Question tools

Follow
2 followers

Stats

Asked: 2016-09-03 16:54:11 +0300

Seen: 210 times

Last updated: Sep 03 '16