Qt: Use header resize mode for memory card editor

pull/3499/head
Stenzek 3 months ago
parent c6c8039211
commit 93d6fc64da
No known key found for this signature in database

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

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

@ -153,9 +153,15 @@ static void SetColumnWidthForView(T* const view, QHeaderView* const header, cons
int column_index = 0; int column_index = 0;
for (const int width : widths) 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); view->setColumnWidth(column_index, width);
}
column_index++; column_index++;
} }

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

Loading…
Cancel
Save