From bdf8034fb1a4dc33cf87f67ecf6e4c2c6cfb08be Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Wed, 2 Dec 2015 17:51:00 -0800 Subject: [PATCH] Qt: Disable setStretchLastSection in the packet list. QTreeView sets the stretchLastSection property of its header by default. In our case this means that if the sum of our recent column widths exceeds the width of the packet list viewport QHeaderView will shrink the last column to fit. Disable setStretchLastSection. We want its behavior when our columns are too narrow so check for that in ::showEvent and temporarily enable it there. Bug: 11738 Change-Id: Ia4aad63e4f4bf899891bcebb7032dc5ebeb74cc7 Reviewed-on: https://code.wireshark.org/review/12392 Reviewed-by: Gerald Combs Petri-Dish: Gerald Combs Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman --- ui/qt/packet_list.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ui/qt/packet_list.cpp b/ui/qt/packet_list.cpp index a2f565505d..b1b665fc3b 100644 --- a/ui/qt/packet_list.cpp +++ b/ui/qt/packet_list.cpp @@ -262,6 +262,8 @@ PacketList::PacketList(QWidget *parent) : setUniformRowHeights(true); setAccessibleName("Packet list"); + header()->setStretchLastSection(false); + overlay_sb_ = new OverlayScrollBar(Qt::Vertical, this); setVerticalScrollBar(overlay_sb_); @@ -430,6 +432,17 @@ PacketListModel *PacketList::packetListModel() const { void PacketList::showEvent (QShowEvent *) { setColumnVisibility(); + + int column_width = 0; + for (int col = 0; col < packet_list_model_->columnCount(); col++) { + column_width += columnWidth(col); + } + + if (column_width < viewport()->width()) { + header()->setStretchLastSection(true); + applyRecentColumnWidths(); + header()->setStretchLastSection(false); + } } void PacketList::selectionChanged (const QItemSelection & selected, const QItemSelection & deselected) { @@ -703,11 +716,16 @@ void PacketList::fieldsChanged(capture_file *cf) // Called via recentFilesRead. void PacketList::applyRecentColumnWidths() { +// bool saved_stretch = header()->stretchLastSection(); +// header()->setStretchLastSection(false); + // Either we've just started up or a profile has changed. Read // the recent settings, apply them, and save the header state. for (int col = 0; col < prefs.num_cols; col++) { setRecentColumnWidth(col); } + +// header()->setStretchLastSection(saved_stretch); column_state_ = header()->saveState(); }