diff --git a/src/widgets/data/ItemListView.cpp b/src/widgets/data/ItemListView.cpp index aef7b9f0b..b1fe05bad 100644 --- a/src/widgets/data/ItemListView.cpp +++ b/src/widgets/data/ItemListView.cpp @@ -2,7 +2,6 @@ // SPDX-License-Identifier: LGPL-3.0-or-later #include - #include #include #include @@ -18,6 +17,7 @@ ItemListView::ItemListView(QWidget *parent) setSelectionBehavior(QAbstractItemView::SelectRows); setEditTriggers(QAbstractItemView::AllEditTriggers); setItemDelegate(new ItemSelectionDelegate(this)); + horizontalHeader()->setStretchLastSection(true); ItemSelector itemSelector; m_columnWidth[0] = itemSelector.combo_type_width(); @@ -31,6 +31,9 @@ ItemListView::ItemListView(QWidget *parent) itemSelector.close(); itemSelector.deleteLater(); + if (style()->name() == "oxygen") + setFixedWidth(width() + 8); + } void ItemListView::setModel(QAbstractItemModel *model) @@ -80,6 +83,30 @@ int ItemListView::sizeHintForColumn(int column) return m_columnWidth[column]; } +void ItemListView::changeEvent(QEvent *e) +{ + if (e->type() == QEvent::StyleChange) { + ItemSelector itemSelector; + m_columnWidth[0] = itemSelector.combo_type_width(); + m_columnWidth[1] = itemSelector.combo_item_width(); + m_columnWidth[2] = itemSelector.qty_width(); + setFixedWidth(itemSelector.sizeHint().width() + verticalScrollBar()->sizeHint().width()); + verticalHeader()->setDefaultSectionSize(itemSelector.height()); + itemSelector.close(); + itemSelector.deleteLater(); + setColumnWidth(0, m_columnWidth[0]); + setColumnWidth(1, m_columnWidth[1]); + setColumnWidth(2, m_columnWidth[2]); + if (style()->name() == "breeze") + setFixedWidth(width() + 4); + if (style()->name() == "oxygen") + setFixedWidth(width() + 8); + } else { + QWidget::changeEvent(e); + } + adjustSize(); +} + void ItemListView::setMaximumItemQty(int itemQtyLimit) { if(m_itemQtyLimit == itemQtyLimit) diff --git a/src/widgets/data/ItemListView.h b/src/widgets/data/ItemListView.h index d49e24b5a..28b5fc4df 100644 --- a/src/widgets/data/ItemListView.h +++ b/src/widgets/data/ItemListView.h @@ -22,6 +22,8 @@ class FF7TKWIDGETS_EXPORT ItemListView : public QTableView bool viewportEvent(QEvent *event); void destroyTooltip(); int sizeHintForColumn(int column); +protected: + void changeEvent(QEvent *e); private: int m_itemQtyLimit = 127; bool m_editableItemCombo = false; diff --git a/src/widgets/data/ItemSelector.cpp b/src/widgets/data/ItemSelector.cpp index 1d0bd7eec..ef4710d46 100644 --- a/src/widgets/data/ItemSelector.cpp +++ b/src/widgets/data/ItemSelector.cpp @@ -40,7 +40,7 @@ void ItemSelector::init_display() btn_remove->setIconSize(iconSize); btn_remove->setIcon(QIcon::fromTheme(QStringLiteral("edit-clear"), QPixmap(":/common/edit-clear"))); btn_remove->setToolTip(tr("Empty Item")); - btn_remove->setFixedWidth((iconSize.width()*2)); + btn_remove->setFixedWidth((fontMetrics().height()*2)); btn_remove->setShortcut(QKeySequence::Delete); init_data(); //before setting layout set dat @@ -114,6 +114,19 @@ void ItemSelector::btn_remove_clicked() Q_EMIT itemChanged(current_item); } +void ItemSelector::changeEvent(QEvent *e) +{ + if (e->type() == QEvent::StyleChange) { + adjustSize(); + } else if (e->type() == QEvent::FontChange) { + qDebug() << "Font Change"; + sb_qty->setFixedWidth(fontMetrics().horizontalAdvance(QStringLiteral("WWWW")) + 3); + btn_remove->setFixedWidth((fontMetrics().height()*2)); + } else { + QWidget::changeEvent(e); + } +} + void ItemSelector::setFilter(int type) { type++;//for hiding no filter. @@ -263,6 +276,7 @@ void ItemSelector::setFixedHeight(int h) combo_type->setFixedHeight(h); combo_item->setFixedHeight(h); btn_remove->setFixedHeight(h); + QWidget::setFixedHeight(h); } void ItemSelector::setFixedWidth(int w) diff --git a/src/widgets/data/ItemSelector.h b/src/widgets/data/ItemSelector.h index c131ab019..66c95096e 100644 --- a/src/widgets/data/ItemSelector.h +++ b/src/widgets/data/ItemSelector.h @@ -35,6 +35,8 @@ private slots: void comboItem_changed(int index); void sb_qty_changed(int qty); void btn_remove_clicked(); +protected: + void changeEvent(QEvent *e); private: void init_display(); void init_connections();