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. How to implement a scrollbar for Qframe in which user add many labels by clicking button
Forum Updated to NodeBB v4.3 + New Features

How to implement a scrollbar for Qframe in which user add many labels by clicking button

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 3 Posters 6.3k 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.
  • dheerendraD Offline
    dheerendraD Offline
    dheerendra
    Qt Champions 2022
    wrote on last edited by
    #2

    How about using the QScrollArea class. Sample example is already in given the Qt documentation for this. You can check Qt Documentation for this.

    Dheerendra
    @Community Service
    Certified Qt Specialist
    http://www.pthinks.com

    1 Reply Last reply
    5
    • S Offline
      S Offline
      sanjay1155
      wrote on last edited by
      #3

      @dheerendra I have already read it but couldn't understand how can i implement it for my Qframe.

      1 Reply Last reply
      0
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Qt Champions 2022
        wrote on last edited by
        #4

        You can check this ? Your Frame is also Qwidget only as it inherits from QWidget.
        scrollArea = new QScrollArea;
        scrollArea->setBackgroundRole(QPalette::Dark);
        scrollArea->setWidget(<yourframeobject>);

        Question - Why do you want QFrame ?

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        1 Reply Last reply
        5
        • S Offline
          S Offline
          sanjay1155
          wrote on last edited by
          #5

          I have used QFrame to divide my screen into three parts and in each part different elements are show like for a paint application we have a left palette for showing elements then a centre palette for adding elements(only here i want to add scrollarea)and a third one the right side for showing the all the data inputed in those QTextEdit at the centre.

          1 Reply Last reply
          0
          • dheerendraD Offline
            dheerendraD Offline
            dheerendra
            Qt Champions 2022
            wrote on last edited by
            #6

            Ok. got it. It should work.

            Dheerendra
            @Community Service
            Certified Qt Specialist
            http://www.pthinks.com

            1 Reply Last reply
            4
            • S Offline
              S Offline
              sanjay1155
              wrote on last edited by
              #7

              It is showing a scrollarea at the top left corner and i have used it for my QFrame which is placed at the centre of the screen.

              1 Reply Last reply
              0
              • dheerendraD Offline
                dheerendraD Offline
                dheerendra
                Qt Champions 2022
                wrote on last edited by
                #8

                Must be some logic issue. Can you give sample code ?

                Dheerendra
                @Community Service
                Certified Qt Specialist
                http://www.pthinks.com

                1 Reply Last reply
                4
                • dheerendraD Offline
                  dheerendraD Offline
                  dheerendra
                  Qt Champions 2022
                  wrote on last edited by
                  #9

                  I tried something like follows. It works perfectly without any issue. This shows the scrollbar when frame size incrases.

                  this->m_Area = new QScrollArea;
                  this->m_Frame = new QFrame;
                  this->m_Frame->setFixedSize(2000,800);
                  
                  this->m_Frame->setFrameStyle(QFrame::Panel | QFrame::Raised);
                  this->m_Area->setWidget(m_Frame);
                  this->m_Area->show();
                  

                  Dheerendra
                  @Community Service
                  Certified Qt Specialist
                  http://www.pthinks.com

                  1 Reply Last reply
                  5
                  • S Offline
                    S Offline
                    sanjay1155
                    wrote on last edited by
                    #10

                    mainwindow.cpp

                    MainWindow::MainWindow(QWidget *parent) :
                    QMainWindow(parent),
                    ui(new Ui::MainWindow)
                    {
                    ui->setupUi(this);
                    edit = new QTextEdit(this);
                    wordLabel = new QLabel(this);
                    m_Area = new QScrollArea(this);
                    m_Frame = new QFrame(this);
                    m_Frame->setFixedSize(2000,800);
                    m_Frame->setFrameStyle(QFrame::Panel | QFrame::Raised);
                    m_Area->setWidget(m_Frame);
                    m_Area->show();
                    }
                    Still showing the scrollarea at the top left corner only

                    1 Reply Last reply
                    0
                    • dheerendraD Offline
                      dheerendraD Offline
                      dheerendra
                      Qt Champions 2022
                      wrote on last edited by
                      #11

                      As I said it is logic issue. Please create separate widget class. Inside the constructor You should do like this. Create ui object. Create texfield. Create other object. Add all them to horizontal layout. Set the horizontal layout to your frame. Set the frame to scroll area. Please don't pass the parent to frame, scrollarea.

                      Dheerendra
                      @Community Service
                      Certified Qt Specialist
                      http://www.pthinks.com

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

                        Hi,

                        That's because m_Area is a "free" widget, you don't put it as central widget of your QMainWindow subclass thus it's put on the default location (0, 0) which happens to be top left. It will also not get resized automatically since it's not part of any layout. In the case of QMainWindow, like I wrote before, you can set it as central widget.

                        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