1
votes

I am using JSON to receive data and place it into List. There is a Label displaying the text that I am receiving from the JSON. In some of the cases there is a Link in the text. By default you can't click on the Link from the label. Is there a way to make the Link to be clickable?

Label {
       text:  "Click here to open browser and get redirected to www.stackoverflow.com";
       }

The output is "Click here to open browser and get redirected to www.stackoverflow.com" but the Link to StackOverflow is not clickable.

3

3 Answers

2
votes

Use TextArea instead of Label and set property editable to false, it would look same as Label. Don't forget to set inputMode to either Text or Chat.

TextArea {
        text: "http://www.google.com"
        editable: false
        inputMode: TextAreaInputMode.Text
}
2
votes

You can actually use HTML in the label itself to style the text as a link, according to the Text Styles documentation. You need to be aware of a few quirks though if you are going to apply any of your own styles, as discussed on the Blackberry Developer support forums here. The example below should work, using the default style which will colour the link blue, with bold and underline:

Label {
    text: "<html>Click here to open browser and get redirected to <a href='http://www.stackoverflow.com'>www.stackoverflow.com</a></html>"
}

Note: you may need to set multiline: true on the Label in order to see all of the text, depending on your layout.

1
votes

You should assign Text.RichText value to "textFormat" property of the Label:

import QtQuick 1.1

Rectangle {
  width: 360
  height: 360
  Text {
    text: "Click <a href=\"http://google.com\">here</a>"
    anchors.centerIn: parent
    textFormat: Text.RichText
    onLinkActivated: {
      Qt.openUrlExternally(link)
    }
  }
}