Qt: Use header resize mode for memory card editor

This commit is contained in:
Stenzek 2025-08-07 21:14:06 +10:00
parent c6c8039211
commit 93d6fc64da
No known key found for this signature in database
4 changed files with 14 additions and 9 deletions

View File

@ -52,6 +52,9 @@ MemoryCardEditorWindow::MemoryCardEditorWindow() : QWidget()
m_card_b.table = m_ui.cardB;
m_card_b.blocks_free_label = m_ui.cardBUsage;
QtUtils::SetColumnWidthsForTableView(m_card_a.table, {32, -1, 155, 45});
QtUtils::SetColumnWidthsForTableView(m_card_b.table, {32, -1, 155, 45});
createCardButtons(&m_card_a, m_ui.buttonBoxA);
createCardButtons(&m_card_b, m_ui.buttonBoxB);
connectUi();
@ -114,12 +117,6 @@ bool MemoryCardEditorWindow::createMemoryCard(const QString& path, Error* error)
return MemoryCardImage::SaveToFile(*data.get(), path.toUtf8().constData(), error);
}
void MemoryCardEditorWindow::resizeEvent(QResizeEvent* ev)
{
QtUtils::ResizeColumnsForTableView(m_card_a.table, {32, -1, 155, 45});
QtUtils::ResizeColumnsForTableView(m_card_b.table, {32, -1, 155, 45});
}
void MemoryCardEditorWindow::closeEvent(QCloseEvent* ev)
{
m_card_a.path_cb->setCurrentIndex(0);
@ -303,10 +300,12 @@ void MemoryCardEditorWindow::updateCardTable(Card* card)
card->table->setItem(row, 1, item);
item = new QTableWidgetItem(QString::fromStdString(fi.filename));
item->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
setCardTableItemProperties(item, fi);
card->table->setItem(row, 2, item);
item = new QTableWidgetItem(QString::number(fi.num_blocks));
item->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
setCardTableItemProperties(item, fi);
card->table->setItem(row, 3, item);
}

View File

@ -31,7 +31,6 @@ public:
static bool createMemoryCard(const QString& path, Error* error);
protected:
void resizeEvent(QResizeEvent* ev);
void closeEvent(QCloseEvent* ev);
private Q_SLOTS:

View File

@ -153,9 +153,15 @@ static void SetColumnWidthForView(T* const view, QHeaderView* const header, cons
int column_index = 0;
for (const int width : widths)
{
header->setSectionResizeMode(column_index, (width < 0) ? QHeaderView::Stretch : QHeaderView::Fixed);
if (width > 0)
if (width <= 0)
{
header->setSectionResizeMode(column_index, (width < 0) ? QHeaderView::Stretch : QHeaderView::ResizeToContents);
}
else
{
header->setSectionResizeMode(column_index, QHeaderView::Fixed);
view->setColumnWidth(column_index, width);
}
column_index++;
}

View File

@ -76,6 +76,7 @@ void ResizeColumnsForTableView(QTableView* view, const std::initializer_list<int
void ResizeColumnsForTreeView(QTreeView* view, const std::initializer_list<int>& widths);
/// For any positive values, sets the corresponding column width to the specified value.
/// Any values of 0 will set the column's width based on the content.
/// Any values of -1 will stretch the column to use the remaining space.
void SetColumnWidthsForTableView(QTableView* view, const std::initializer_list<int>& widths);
void SetColumnWidthsForTreeView(QTreeView* view, const std::initializer_list<int>& widths);