Scroll area not scrollable
Unsolved
General and Desktop
-
Hey, I have an issue getting my scroll area UI started using QT 5.12.2 in visual studio...
I have a scroll area with 2 images in it, as can be seen in the image below the scroll bar is there but inactive:
This is how I open my UI with the scroll area:
scrollUI* w = new scrollUI(this); w->setWindowFlags(Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint); w->show();
and here is the code found in the .ui file:
/******************************************************************************** ** Form generated from reading UI file 'scrollUI.ui' ** ** Created by: Qt User Interface Compiler version 5.15.2 ** ** WARNING! All changes made in this file will be lost when recompiling UI file! ********************************************************************************/ #ifndef UI_SCROLLUI_H #define UI_SCROLLUI_H #include <QtCore/QVariant> #include <QtWidgets/QApplication> #include <QtWidgets/QLabel> #include <QtWidgets/QPushButton> #include <QtWidgets/QScrollArea> #include <QtWidgets/QWidget> QT_BEGIN_NAMESPACE class Ui_scrollUIUI { public: QPushButton *quitButton; QScrollArea *scrollArea; QWidget *scrollAreaWidgetContents; QLabel *label; QLabel *label_2; void setupUi(QWidget *scrollUIUI) { if (scrollUIUI->objectName().isEmpty()) scrollUIUI->setObjectName(QString::fromUtf8("scrollUIUI")); scrollUIUI->resize(969, 1081); quitButton = new QPushButton(scrollUIUI); quitButton->setObjectName(QString::fromUtf8("quitButton")); quitButton->setGeometry(QRect(860, 10, 100, 100)); quitButton->setMinimumSize(QSize(100, 100)); quitButton->setMaximumSize(QSize(100, 100)); QFont font; font.setPointSize(14); font.setUnderline(true); quitButton->setFont(font); quitButton->setCursor(QCursor(Qt::ArrowCursor)); quitButton->setStyleSheet(QString::fromUtf8("")); scrollArea = new QScrollArea(scrollUIUI); scrollArea->setObjectName(QString::fromUtf8("scrollArea")); scrollArea->setGeometry(QRect(10, 10, 841, 1061)); QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); sizePolicy.setHorizontalStretch(0); sizePolicy.setVerticalStretch(0); sizePolicy.setHeightForWidth(scrollArea->sizePolicy().hasHeightForWidth()); scrollArea->setSizePolicy(sizePolicy); scrollArea->setMinimumSize(QSize(841, 1061)); scrollArea->setMaximumSize(QSize(841, 9999)); scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); scrollArea->setWidgetResizable(true); scrollAreaWidgetContents = new QWidget(); scrollAreaWidgetContents->setObjectName(QString::fromUtf8("scrollAreaWidgetContents")); scrollAreaWidgetContents->setGeometry(QRect(0, 0, 822, 1059)); label = new QLabel(scrollAreaWidgetContents); label->setObjectName(QString::fromUtf8("label")); label->setGeometry(QRect(10, 10, 791, 1041)); label->setPixmap(QPixmap(QString::fromUtf8("../../../../../../Users/xxxx/Pictures/scrollUI1.PNG"))); label_2 = new QLabel(scrollAreaWidgetContents); label_2->setObjectName(QString::fromUtf8("label_2")); label_2->setGeometry(QRect(10, 1050, 791, 541)); label_2->setPixmap(QPixmap(QString::fromUtf8("../../../../../../Users/xxxx/Pictures/scrollUI2.PNG"))); scrollArea->setWidget(scrollAreaWidgetContents); retranslateUi(scrollUIUI); QObject::connect(quitButton, SIGNAL(clicked()), scrollUIUI, SLOT(deleteLater())); QMetaObject::connectSlotsByName(scrollUIUI); } // setupUi void retranslateUi(QWidget *scrollUIUI) { scrollUIUI->setWindowTitle(QCoreApplication::translate("scrollUIUI", "Form", nullptr)); quitButton->setText(QCoreApplication::translate("scrollUIUI", "Quit", nullptr)); label->setText(QString()); label_2->setText(QString()); } // retranslateUi }; namespace Ui { class scrollUIUI: public Ui_scrollUIUI {}; } // namespace Ui QT_END_NAMESPACE #endif // UI_SCROLLUI_H
The .h file for the scrollbar is following:
#pragma once #include "ui_scrollUI.h" class scrollUI : public QWidget { Q_OBJECT public: scrollUI(QWidget* parent = nullptr); private: Ui::scrollUIUI ui; };
The .cpp file:
#include "scrollUI.h" scrollUI::scrollUI(QWidget* parent) { ui.setupUi(this); }
apologies for the poor names, tried to rename my variables... and sorry if it is a common question.