From 2c796e4b7b2af7aace8fd51e42cd4319f2239fde Mon Sep 17 00:00:00 2001 From: jp9000 Date: Sat, 3 Jan 2015 02:42:57 -0800 Subject: [PATCH] UI: Add vertical scroll area subclass The regular scroll area can expand horizontally, but the problem with this is that sometimes there are controls within it that expand way too big. For example, the properties window for window capture can have a list of windows where the titles of the windows are really really long, and it causes the properties to extend way too far to the right, making the window look really unusual. Another example are the volume controls in the main window that can expand way to the right if the name of a source is really long, causing the volume control to stretch way too far to the right, making the volume controls difficult to use when that happens. So this just makes it so it sets the maximum width of a scroll area's internal widget to the actual width of the scroll area, preventing it from going off the side of the scroll area. --- obs/CMakeLists.txt | 2 ++ obs/vertical-scroll-area.cpp | 8 ++++++++ obs/vertical-scroll-area.hpp | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 obs/vertical-scroll-area.cpp create mode 100644 obs/vertical-scroll-area.hpp diff --git a/obs/CMakeLists.txt b/obs/CMakeLists.txt index 4353f77f2..c5cebf8c3 100644 --- a/obs/CMakeLists.txt +++ b/obs/CMakeLists.txt @@ -105,6 +105,7 @@ set(obs_SOURCES properties-view.cpp volume-control.cpp adv-audio-control.cpp + vertical-scroll-area.cpp crash-report.cpp qt-wrappers.cpp) @@ -129,6 +130,7 @@ set(obs_HEADERS display-helpers.hpp volume-control.hpp adv-audio-control.hpp + vertical-scroll-area.hpp qt-display.hpp crash-report.hpp qt-wrappers.hpp) diff --git a/obs/vertical-scroll-area.cpp b/obs/vertical-scroll-area.cpp new file mode 100644 index 000000000..d23d386b2 --- /dev/null +++ b/obs/vertical-scroll-area.cpp @@ -0,0 +1,8 @@ +#include +#include "vertical-scroll-area.hpp" + +void VScrollArea::resizeEvent(QResizeEvent *event) +{ + if (!!widget()) + widget()->setMaximumWidth(event->size().width()); +} diff --git a/obs/vertical-scroll-area.hpp b/obs/vertical-scroll-area.hpp new file mode 100644 index 000000000..73ab1bbc6 --- /dev/null +++ b/obs/vertical-scroll-area.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include + +class QResizeEvent; + +class VScrollArea : public QScrollArea { + Q_OBJECT + +public: + inline VScrollArea(QWidget *parent = nullptr) + : QScrollArea(parent) + { + } + +protected: + virtual void resizeEvent(QResizeEvent *event) override; +};