From 4e361f93fe717b05a284dd29319e91a9b574c7ea Mon Sep 17 00:00:00 2001 From: Kellermorph Date: Wed, 23 Sep 2026 10:27:50 +0200 Subject: [PATCH] Let the PLC master IO table columns be resized, and remember the layout The IO table of MasterPropertiesWidget -- the panel that opens when a PLC master placed on a schematic is edited -- set every section to QHeaderView::Stretch. Stretch spreads the sections evenly over the widget and disables section dragging altogether, so the column boundaries were permanently fixed: they could be neither widened nor narrowed, and only the width of the whole panel had any effect. Use QHeaderView::Interactive instead, with movable sections and a set of default widths, so the columns can be dragged as they are everywhere else in the application. The layout reached this way is written to QSettings under masterpropertieswidget/plc-table-header-state on every sectionResized and sectionMoved, and restored the next time the table is built -- the same header-state trick the free and linked element trees of this widget already use, except saved automatically rather than only from the context menu. --- sources/ui/masterpropertieswidget.cpp | 30 ++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/sources/ui/masterpropertieswidget.cpp b/sources/ui/masterpropertieswidget.cpp index 339938d06..94d56e145 100644 --- a/sources/ui/masterpropertieswidget.cpp +++ b/sources/ui/masterpropertieswidget.cpp @@ -539,7 +539,35 @@ void MasterPropertiesWidget::updateUi() tr("Type"), tr("Adresse"), tr("Fonction"), tr("Commentaire"), tr("Réf. croisée"), tr("Bornes") }); - m_plc_table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); + m_plc_table->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); + m_plc_table->horizontalHeader()->setSectionsMovable(true); + m_plc_table->horizontalHeader()->resizeSection(0, 120); + m_plc_table->horizontalHeader()->resizeSection(1, 100); + m_plc_table->horizontalHeader()->resizeSection(2, 150); + m_plc_table->horizontalHeader()->resizeSection(3, 150); + m_plc_table->horizontalHeader()->resizeSection(4, 100); + m_plc_table->horizontalHeader()->resizeSection(5, 120); + + // Restore a previously saved column layout, if any + auto *plc_hdr = m_plc_table->horizontalHeader(); + QSettings plc_settings; + const QVariant plc_hdr_state = plc_settings.value( + QStringLiteral("masterpropertieswidget/plc-table-header-state")); + if (!plc_hdr_state.isNull()) + plc_hdr->restoreState(plc_hdr_state.toByteArray()); + + // Persist the column layout whenever the user resizes or moves a column + auto save_plc_header_state = [plc_hdr]() + { + QSettings settings; + settings.setValue(QStringLiteral("masterpropertieswidget/plc-table-header-state"), + plc_hdr->saveState()); + }; + connect(plc_hdr, &QHeaderView::sectionResized, + this, save_plc_header_state); + connect(plc_hdr, &QHeaderView::sectionMoved, + this, save_plc_header_state); + m_plc_table->setSelectionBehavior(QAbstractItemView::SelectItems); m_plc_table->setSelectionMode(QAbstractItemView::ExtendedSelection); m_plc_table->setMinimumHeight(200);