Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QScrollArea Image Loading
Qt 6.11 is out! See what's new in the release blog

QScrollArea Image Loading

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.0k 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.
  • T Offline
    T Offline
    Thanasis
    wrote on last edited by
    #1

    Hello, everybody,

    I am trying to modify the "scribble" Qt example and load an image inside a QWidget and add scrollbars if the image is larger than the Main Window.

    I have these two classes:

    class MainWindow: public QMainWindow
    class ImageViewer: public QWidget
    

    Inside the constructor of the MainWindow, I have added the following code.

    QScrollArea *scroll_area_ = new QScrollArea();
    main_area_ = new ImageViewer(scroll_area_);
    QHBoxLayout *mainLayout = new QHBoxLayout();
    QTextEdit *te = new QTextEdit("1234"); // Added also a text box just for testing
    mainLayout->addWidget(main_area_);
    mainLayout->addWidget(te);
    scroll_area_->setWidgetResizable(true);
    scroll_area_->setWidget(main_area_);
    scroll_area_->setLayout(mainLayout);
    setCentralWidget(scroll_area_);
    setWindowTitle(tr("Show Image"));
    

    and in my main I have added the following code:

    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
        MainWindow window;
        window.show();
        return app.exec();
    }
    

    My problem is that the widgets are being loaded one behind the other and when I am loading a large image file the scrollbars do not appear.

    Do you have any ideas what I am doing wrong.?

    Thank you in advance for your help.
    Thanasis

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

      Hi and welcome to devnet,

      You are setting a layout and a widget on your scroll_area which is wrong. From your description, you should rather have your ImageViewer as widget of the QScrollArea and then the QScrollArea in a layout on top your QTextEdit.

      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
      0

      • Login

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