From acf63490959d63a1a7859f883fe05d6475942e30 Mon Sep 17 00:00:00 2001 From: "tatiana.novikova" <tatiana.novikova@demlabs.net> Date: Tue, 14 Jan 2020 10:45:07 +0300 Subject: [PATCH] [*] Update calculating and deleting the unnecessary part of text at comboBox --- widgets/DapComboBox.qml | 21 +++++++++++---------- widgets/DapComboBoxForm.ui.qml | 1 - 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/widgets/DapComboBox.qml b/widgets/DapComboBox.qml index 8bd71b4..d5203e5 100644 --- a/widgets/DapComboBox.qml +++ b/widgets/DapComboBox.qml @@ -1,13 +1,10 @@ -import QtQuick 2.7 +import QtQuick 2.4 import QtQuick.Controls 2.0 DapComboBoxForm { id:dapComboBox - //temporary variable for the calculating unnecessary part of text - property int stringSize - delegate:ItemDelegate { @@ -33,6 +30,7 @@ DapComboBoxForm anchors.fill: parent anchors.topMargin: paddingTopItemDelegate anchors.leftMargin: popup.visible ? sidePaddingActive : sidePaddingNormal + anchors.rightMargin: popup.visible ? sidePaddingActive : sidePaddingNormal font:dapComboBox.font //Calculates various properties of a given string of text for a particular font TextMetrics @@ -40,19 +38,22 @@ DapComboBoxForm id: tm font: dapComboBox.font elide: Text.ElideRight - elideWidth: parent.width - (popup.visible ? sidePaddingActive : sidePaddingNormal) * 2 - 8*pt text: modelData + elideWidth: + { + if(index != currentIndex) + return widthPopupComboBoxActive - 2*sidePaddingActive; + else + return widthPopupComboBoxNormal - indicatorWidth ; + } } text: { if(index != currentIndex) - return modelData; + return tm.elidedText.replace('…', '..'); else { - stringSize = tm.elidedText.length; - if(stringSize < modelData.length) - mainLineText = tm.elidedText.substring(0, stringSize-3) + '..'; - else mainLineText = modelData; + mainLineText = tm.elidedText.replace('…', '..'); return ""; } } diff --git a/widgets/DapComboBoxForm.ui.qml b/widgets/DapComboBoxForm.ui.qml index c16956c..a46345d 100644 --- a/widgets/DapComboBoxForm.ui.qml +++ b/widgets/DapComboBoxForm.ui.qml @@ -67,7 +67,6 @@ ComboBox property string colorDropShadow ///@detalis fontComboBox Font setting combobox. property alias fontComboBox:customComboBox.font - ///@detalis mainLineText Text without unneccesary part property string mainLineText -- GitLab