11// Copyright (C) 2019 ~ 2020 Uniontech Software Technology Co.,Ltd
2- // SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
2+ // SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd.
33//
44// SPDX-License-Identifier: GPL-3.0-or-later
55
@@ -86,7 +86,7 @@ void ItemWidget::setFuncIcon(ItemFuncType iconType)
8686{
8787 qCDebug (views) << " Enter ItemWidget::setFuncIcon" ;
8888 // 统一设置大小
89- m_funcButton->setIconSize (QSize (20 , 20 ));
89+ m_funcButton->setIconSize (QSize (16 , 16 ));
9090 m_deleteButton->setIconSize (QSize (20 , 20 ));
9191 m_deleteButton->hide ();
9292 switch (iconType) {
@@ -341,16 +341,18 @@ void ItemWidget::updateSizeMode()
341341{
342342 qCDebug (views) << " Enter ItemWidget::updateSizeMode" ;
343343#ifdef DTKWIDGET_CLASS_DSizeMode
344+ // 设置最小宽度,防止挤压,允许宽度自适应
345+ setMinimumWidth (220 );
344346 if (DGuiApplicationHelper::isCompactMode ()) {
345347 qCDebug (views) << " Branch: compact mode" ;
346348 m_iconLayout->setContentsMargins (s_ItemIconContentMarginsCompact);
347- setFixedSize ( 220 , s_ItemHeightCompact);
349+ setFixedHeight ( s_ItemHeightCompact);
348350 setFont (m_firstline, DFontSizeManager::T6, ItemTextColor_Text);
349351 setFont (m_secondline, DFontSizeManager::T7, ItemTextColor_TextTips);
350352 } else {
351353 qCDebug (views) << " Branch: normal mode" ;
352354 m_iconLayout->setContentsMargins (s_ItemIconContentMargins);
353- setFixedSize ( 220 , s_ItemHeight);
355+ setFixedHeight ( s_ItemHeight);
354356 setFont (m_firstline, DFontSizeManager::T7, ItemTextColor_Text);
355357 setFont (m_secondline, DFontSizeManager::T8, ItemTextColor_TextTips);
356358 }
@@ -362,14 +364,9 @@ void ItemWidget::initUI()
362364{
363365 if (m_functType != ItemFuncType_GroupLabel && m_functType != ItemFuncType_ItemLabel)
364366 {
365- // 初始化控件大小
366- if (m_functType == ItemFuncType_UngroupedItem) {
367- setGeometry (0 , 0 , 360 , 60 );
368- setFixedSize (360 , 60 );
369- } else {
370- setGeometry (0 , 0 , 220 , 60 );
371- setFixedSize (220 , 60 );
372- }
367+ // 设置最小宽度,防止挤压,允许宽度自适应
368+ setMinimumWidth (220 );
369+ setFixedHeight (60 );
373370 }
374371 else
375372 {
@@ -396,12 +393,13 @@ void ItemWidget::initUI()
396393 setFont (m_secondline, DFontSizeManager::T8, ItemTextColor_TextTips);
397394 m_firstline->setContentsMargins (0 , 0 , 0 , 0 );
398395 m_secondline->setContentsMargins (0 , 0 , 0 , 0 );
399- m_firstline->setFixedWidth (138 );
400- m_secondline->setFixedWidth (138 );
396+ m_firstline->setMaximumWidth (138 );
397+ m_secondline->setMaximumWidth (138 );
401398 m_textLayout->setContentsMargins (0 , 0 , 0 , 0 );
402399 m_textLayout->setSpacing (0 );
403400 m_textLayout->addStretch (13 );
404401 m_textLayout->addWidget (m_firstline, 13 );
402+ m_textLayout->setAlignment (m_firstline, Qt::AlignLeft);
405403 m_textLayout->addStretch (9 );
406404 if (m_functType != ItemFuncType_GroupLabel && m_functType != ItemFuncType_ItemLabel)
407405 {
@@ -418,10 +416,10 @@ void ItemWidget::initUI()
418416 m_funcButton->setFlat (true );
419417 m_funcButton->setFocusPolicy (Qt::NoFocus);
420418 m_funcLayout->addStretch ();
421- m_funcLayout->setContentsMargins (5 , 0 , 5 , 0 );
419+ m_funcLayout->setContentsMargins (5 , 0 , 10 , 0 );
422420 m_funcLayout->addWidget (m_deleteButton);
423421 m_funcLayout->addWidget (m_funcButton);
424- m_funcLayout->addStretch ( );
422+ m_funcLayout->setSpacing ( 5 );
425423
426424 // 整体布局
427425 m_mainLayout->setContentsMargins (0 , 0 , 0 , 0 );
@@ -433,16 +431,15 @@ void ItemWidget::initUI()
433431 m_checkBox->hide ();
434432 }
435433 m_mainLayout->addLayout (m_iconLayout);
436- m_mainLayout->addLayout (m_textLayout);
434+ m_mainLayout->addLayout (m_textLayout, 1 );
437435 m_mainLayout->addLayout (m_funcLayout);
438436 } else {
439437 m_checkBox->hide ();
440438 m_iconButton->hide ();
441- m_mainLayout->addLayout (m_textLayout);
439+ m_mainLayout->addLayout (m_textLayout, 1 );
442440 m_deleteButton->hide ();
443441 m_funcButton->hide ();
444442 }
445- m_mainLayout->addStretch ();
446443 setLayout (m_mainLayout);
447444
448445 // 根据不同布局初始化界面
0 commit comments