Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Qt ScrollArea
Forum Updated to NodeBB v4.3 + New Features

Qt ScrollArea

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
3 Posts 2 Posters 243 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Eugene_Mino
    wrote on last edited by
    #1

    Hello, gurus! I am making a simple project *** for loading large images with scrolling. This version does not work. I know Qt examples and other examples, based on dynamically placing an QLabel i widget n a scroll area. For my task, I need to work with a QLabel placed in a scroll area in Qt designer UI. Has anyone managed to achieve scrolling in similiar project version?

    *** Step-by-Step Guide
    Design the UI in Qt Designer:
    Open Qt Designer and create a new MainWindow form.
    Drag a QScrollArea widget from the widget box and place it in the
    central widget area.
    Drag a QLabel widget and place it inside the QScrollArea.
    Set the QLabel’s objectName to imageLabel.
    Set the QScrollArea’s objectName to scrollArea.
    Ensure the QScrollArea’s widgetResizable property is set to true.
    Ensure the QLabel’s scaledContents property is set to true.
    Save the UI File:
    Save the form as mainwindow.ui.
    Generate the UI Header File:
    Use the uic tool to generate the header file from the .ui file:
    uic mainwindow.ui -o ui_mainwindow.h

    Create the Main Application Code:
    Create a new C++ source file (e.g., main.cpp) and include the generated header file.
    Example Code
    #include <QApplication>
    #include <QMainWindow>
    #include <QScrollArea>
    #include <QLabel>
    #include "ui_mainwindow.h"

    class MainWindow : public QMainWindow {
    Q_OBJECT

    public:
    MainWindow(QWidget *parent = nullptr) : QMainWindow(parent), ui(new Ui::MainWindow) {
    ui->setupUi(this);

        // Load an image and set it to the QLabel
        QPixmap pixmap("path/to/your/image.jpg");
        ui->imageLabel->setPixmap(pixmap);
    }
    
    ~MainWindow() {
        delete ui;
    }
    

    private:
    Ui::MainWindow *ui;
    };

    int main(int argc, char *argv[]) {
    QApplication app(argc, argv);

    MainWindow mainWindow;
    mainWindow.show();
    
    return app.exec();
    

    }

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Did you just put the QLabel there ? If so that is your issue, you have to use a layout to add it to the QWidget that is automatically set on the QScrollArea.

      Other solution: creat the QLabel in the constructor and set it on the QScrollArea to replace the QWidget.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • E Offline
        E Offline
        Eugene_Mino
        wrote on last edited by
        #3

        You are right, the layout in "scrollAreaWidgetContents" solved the problem. Thank you very much.

        1 Reply Last reply
        0
        • SGaistS SGaist has marked this topic as solved on

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved