1
1
12rbah2020-07-21 09:57:32
Qt
12rbah, 2020-07-21 09:57:32

How to show full text if it is larger than Combobox size?

Such a problem is that if the length of the text exceeds the size of the Combobox, then it is displayed as "Example of ... text", is there any way to remove this ellipsis and make the text appear in full?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Flysink, 2020-07-21
@Flysink

You can calculate the width, for example:
ui.qml:

property int minimumWidth: minimumWidth

ComboBox {
        id: comboBox
        width: minimumWidth
        model: ["Пример очень длинного текста", "Текст 2"]
}

in qml:
Component.onCompleted: minimumWidth = resizeComboBox(comboBox)

function resizeComboBox(id) {
      var w = 0;
      if(id.count === 0)
        return id.width;

      var original_index = id.currentIndex;
      if(original_index < 0)
         return id.width;

      do {
           w = Math.max(w, id.contentItem.contentWidth);
           id.currentIndex = (id.currentIndex + 1) % id.count;

      } while(id.currentIndex !== original_index)

      return w + id.contentItem.leftPadding + id.contentItem.rightPadding + id.indicator.width;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question