dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
treewidgetcolumnstretcher.cpp
Go to the documentation of this file.
1 
13 /*
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  * for more details.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, see <http://www.gnu.org/licenses/>
26  */
27 
29 #include <QTreeWidget>
30 #include <QHideEvent>
31 #include <QHeaderView>
32 using namespace Utils;
33 
34 TreeWidgetColumnStretcher::TreeWidgetColumnStretcher(QTreeWidget *treeWidget, int columnToStretch)
35  : QObject(treeWidget->header()), m_columnToStretch(columnToStretch)
36 {
37  parent()->installEventFilter(this);
38  QHideEvent fake;
40 }
41 
42 bool TreeWidgetColumnStretcher::eventFilter(QObject *obj, QEvent *ev)
43 {
44  if (obj == parent()) {
45  if (ev->type() == QEvent::Show) {
46  QHeaderView *hv = qobject_cast<QHeaderView*>(obj);
47  for (int i = 0; i < hv->count(); ++i)
48  hv->setSectionResizeMode(i, QHeaderView::Interactive);
49  } else if (ev->type() == QEvent::Hide) {
50  QHeaderView *hv = qobject_cast<QHeaderView*>(obj);
51  for (int i = 0; i < hv->count(); ++i)
52  hv->setSectionResizeMode(i, i == m_columnToStretch ? QHeaderView::Stretch : QHeaderView::ResizeToContents);
53  } else if (ev->type() == QEvent::Resize) {
54  QHeaderView *hv = qobject_cast<QHeaderView*>(obj);
55  if (hv->sectionResizeMode(m_columnToStretch) == QHeaderView::Interactive) {
56  QResizeEvent *re = static_cast<QResizeEvent*>(ev);
57  int diff = re->size().width() - re->oldSize().width() ;
58  hv->resizeSection(m_columnToStretch, qMax(32, hv->sectionSize(1) + diff));
59  }
60  }
61  }
62  return false;
63 }
diff
Definition: OPPlots.m:68
TreeWidgetColumnStretcher(QTreeWidget *treeWidget, int columnToStretch)
for i
Definition: OPPlots.m:140
bool eventFilter(QObject *obj, QEvent *ev)