BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
AdjustingScrollArea.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Views/CommonWidgets/AdjustingScrollArea.cpp
6 //! @brief Implements class AdjustingScrollArea
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
16 #include <QEvent>
17 #include <QScrollBar>
18 
19 AdjustingScrollArea::AdjustingScrollArea(QWidget* parent) : QScrollArea(parent)
20 {
21  setObjectName("MyScrollArea");
22  setContentsMargins(0, 0, 0, 0);
23  setWidgetResizable(true);
24  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
25  setStyleSheet("QScrollArea#MyScrollArea {border: 0px; background-color:transparent;}");
26 }
27 
29 {
30  QScrollArea::setWidget(w);
31  w->installEventFilter(this);
32 }
33 
35 {
36  QScrollBar* horizontal = horizontalScrollBar();
37  QSize result(viewport()->width(), widget()->height() + horizontal->height() * 2);
38  return result;
39 }
40 
41 bool AdjustingScrollArea::eventFilter(QObject* obj, QEvent* ev)
42 {
43  if (obj == widget() && ev->type() != QEvent::Resize) {
44  widget()->setMaximumWidth(viewport()->width());
45  setMaximumHeight(height() - viewport()->height() + widget()->height());
46  }
47 
48  return QScrollArea::eventFilter(obj, ev);
49 }
Defines class AdjustingScrollArea.
void setWidget(QWidget *w)
bool eventFilter(QObject *obj, QEvent *ev)
AdjustingScrollArea(QWidget *parent=0)