KWidgetsAddons

kadjustingscrollarea.h
1// SPDX-FileCopyrightText: 2007 Klarälvdalens Datakonsult AB
2// SPDX-FileCopyrightText: 2022 g10 Code GmbH
3// SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
4//
5// SPDX-License-Identifier: LGPL-2.1-or-later
6
7#ifndef KADJUSTINGSCROLLAREA_H
8#define KADJUSTINGSCROLLAREA_H
9
10#include <kwidgetsaddons_export.h>
11
12#include <QScrollArea>
13
14/**
15 * @class KAdjustingScrollArea kadjustingscrollarea.h KAdjustingScrollArea
16 *
17 * @short Special scroll area widget which adjust its size to avoid scroll bars
18 * as much as possible
19 *
20 * This widget improves a few aspects of QScrollArea in particular, for
21 * vertically scrollable widgets and dialogs.
22 *
23 * If sizeAdjustPolicy is set to QAbstractScrollArea::AdjustToContents,
24 * then the scroll area will (try to) adjust its size to the widget to avoid
25 * scroll bars as much as possible.
26 *
27 * In particular, this widget will automatically increase the height of its
28 * window when the content of the scroll area grows in height (e.g. because
29 * more widgets are added dynamically). The automatic resizing stops at 2/3
30 * of the screen's height.
31 *
32 * Instead of setting the scrollarea's content via QScrollArea::setWidget,
33 * add the child widgets to the QVBoxLayout of the scrollarea's widget.
34 *
35 * @code{.cpp}
36 * auto scrollArea = new KAdjustingScrollArea(this);
37 * scrollArea->setSizeAdjustPolicy(QScrollArea::AdjustToContents);
38 * scrollArea->setFocusPolicy(Qt::NoFocus);
39 * scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
40 * scrollArea->setWidget(new QWidget);
41 *
42 * auto scrollAreaLayout = new QVBoxLayout(scrollArea->widget());
43 * @endcode
44 *
45 * @since 6.9
46 */
47class KWIDGETSADDONS_EXPORT KAdjustingScrollArea : public QScrollArea
48{
49 Q_OBJECT
50
51public:
52 /**
53 * Creates a scroll area with a QWidget with QVBoxLayout that is flagged
54 * as resizable.
55 */
56 explicit KAdjustingScrollArea(QWidget *parent = nullptr);
57 ~KAdjustingScrollArea() override;
58
59 /**
60 * Reimplemented to add the minimum size hint of the widget.
61 */
62 QSize minimumSizeHint() const override;
63
64 /**
65 * Reimplemented to remove the caching of the size/size hint of the
66 * widget and to add the horizontal size hint of the vertical scroll bar
67 * unless it is explicitly turned off.
68 */
69 QSize sizeHint() const override;
70
71 bool event(QEvent *event) override;
72
73private:
74 bool eventFilter(QObject *obj, QEvent *ev) override;
75};
76
77#endif // KADJUSTINGSCROLLAREA_H
Special scroll area widget which adjust its size to avoid scroll bars as much as possible.
virtual QSize minimumSizeHint() const const override
virtual bool event(QEvent *e) override
virtual bool eventFilter(QObject *o, QEvent *e) override
virtual QSize sizeHint() const const override
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:59:27 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.