-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHorizontalScrollArea.cpp
37 lines (29 loc) · 1.13 KB
/
HorizontalScrollArea.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "HorizontalScrollArea.h"
#include <QWidget>
#include <QHBoxLayout>
#include <QScrollBar>
#include <QEvent>
HorizontalScrollArea::HorizontalScrollArea(QWidget* parent)
: QScrollArea(parent)
{
setWidgetResizable(true);
setFrameStyle(QFrame::NoFrame);
setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_scrollAreaWidgetContents = nullptr;
}
void HorizontalScrollArea::RegisterContentsWidget(QWidget* ScraWidContents)
{
m_scrollAreaWidgetContents = ScraWidContents;
m_scrollAreaWidgetContents->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
m_scrollAreaWidgetContents->installEventFilter(this);
}
bool HorizontalScrollArea::eventFilter(QObject* o, QEvent* e) {
if (o == m_scrollAreaWidgetContents && e->type() == QEvent::Resize) {
int32_t ScrollBarHeight = horizontalScrollBar()->height();
if (!horizontalScrollBar()->isVisible())
ScrollBarHeight = 0;
setMinimumHeight(m_scrollAreaWidgetContents->minimumSizeHint().height() + ScrollBarHeight);
}
return QScrollArea::eventFilter(o, e);
}