Shrink dock panel tabs proportionally in case of overflow

This commit is contained in:
Casper Jeukendrup 2021-12-11 23:51:50 +01:00
parent 2a863701fc
commit e83d551eb0
No known key found for this signature in database
GPG key ID: 6C571BEF59E722DD
2 changed files with 19 additions and 1 deletions

View file

@ -151,11 +151,29 @@ Rectangle {
currentIndex: tabsPanel.currentIndex
model: frameModel.tabs
readonly property real implicitWidthOfActiveTab: currentItem ? currentItem.implicitWidth : 0
readonly property real implicitWidthOfAllTabsTogether: {
let result = 0
for (let i = 0; i < count; i++) {
let item = itemAtIndex(i)
if (item) {
result += item.implicitWidth
}
}
return result
}
delegate: DockPanelTab {
text: modelData.title
isCurrent: tabsPanel && (tabsPanel.currentIndex === model.index)
contextMenuModel: modelData.contextMenuModel
width: isCurrent
? implicitWidth
: Math.min((tabsPanel.width + 1 - tabs.implicitWidthOfActiveTab) // +1, because we don't need the rightmost separator
/ (tabs.implicitWidthOfAllTabsTogether - tabs.implicitWidthOfActiveTab),
1) * implicitWidth
navigation.name: text
navigation.panel: navPanel
navigation.order: model.index * 2 // NOTE '...' button will have +1 order

View file

@ -124,7 +124,7 @@ QQuickItem *TabBarQuick::listView() const
const QList<QQuickItem *> children = m_tabBarQmlItem->childItems();
for (QQuickItem *child : children) {
if (qstrcmp(child->metaObject()->className(), "QQuickListView") == 0)
if (QString::fromUtf8(child->metaObject()->className()).startsWith(QString::fromUtf8("QQuickListView")))
return child;
}