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 <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Gerald Combs 2015-12-02 17:51:00 -08:00 committed by Anders Broman
parent e78093f69f
commit bdf8034fb1
1 changed files with 18 additions and 0 deletions

View File

@ -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();
}