MountainX
MountainX

Reputation: 6337

How to use Text.ElideMiddle in a Label?

I have a label (shown below) that can display fully qualified file names (including full path).

import QtQml.Models 2.2
import QtQuick.Window 2.2
import QtQuick 2.2
import QtQuick.Controls 1.3
import QtQuick.Controls 2.2 as M2
import QtQuick.Layouts 1.3

ApplicationWindow {

    Label {
        id: lblSelectedFileId
        text: selectedFile
        anchors.verticalCenter: parent.verticalCenter
    }
}

These file names came become too long to display properly. I would like to accomplish two things:

  1. Learn how to use Text.ElideMiddle to shorten my text.

  2. Learn how to limit the max width of my Label.

I'm sure there is a readily available answer in the documents if I could understand it. Have checked a number of references including these listed below and I still cannot resolve my issues in Python.

Upvotes: 1

Views: 1049

Answers (1)

eyllanesc
eyllanesc

Reputation: 244093

As Label inherits from Text then you can use that property in the same way. On the other hand there is no maximum width but you have to set the width that will be taken into account for ellipsis.

Label{
    id: lblSelectedFileId
    text: selectedFile
    anchors.verticalCenter: parent.verticalCenter
    elide: Label.ElideMiddle // or Text.ElideMiddle 
    width: 50
}

Upvotes: 1

Related Questions