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
Forum Updated to NodeBB v4.3 + New Features

QScrollArea

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 5.1k 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.
  • K Offline
    K Offline
    kanakas
    wrote on last edited by
    #1

    Hi, I need a little help with my code. I am trying to put scrollbars on my code.
    It is a form that i would like to be in a groupbox and the groupbox in a qvboxlayout.

    @ QVBoxLayout* _layout3;
    QFormLayout* layout;

    QScrollArea *scrollArea = new QScrollArea(this);
        scrollArea->setWidgetResizable(true);
        QGroupBox *groupBox = new QGroupBox(scrollArea);
     
        QWidget *baseArea = new QWidget();
        baseArea->setLayout(_layout3);
        scrollArea->setWidget(baseArea);
     
        while(!patients3.isEmpty()) {
            QMap<QString,QString> patient = patients3.takeFirst();
            if (patient["id"]==itemId) {
                QLineEdit *MyLineEdit = new QLineEdit(patient["id"]);
                layout->addRow("ID",MyLineEdit);
                layout->addRow("Surname", new QLineEdit(patient["surname"]));
                layout->addRow("Name", new QLineEdit(patient["name"]));
        }
        groupBox->setLayout(layout);
        scrollArea->widget()->setLayout(_layout3);
       this->_layout3->addWidget(groupBox);
    }@
    
    1 Reply Last reply
    0
    • K Offline
      K Offline
      kanakas
      wrote on last edited by
      #2

      i changed my code but the scrollbars don't show up.

      @QWidget *window = new QWidget;
      QScrollArea *scrollArea = new QScrollArea(this);
      scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
      scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
      scrollArea->setWidgetResizable(true);

      while(!patients3.isEmpty()) {
      QMap<QString,QString> patient = patients3.takeFirst();
      if (patient["id"]==itemId) {
      QLineEdit *MyLineEdit = new QLineEdit(patient["id"]);
      QFontMetrics metrics(QApplication::font());
      MyLineEdit->setFixedSize(metrics.width("888888888888888888"),20);
      layout->addRow("ID",MyLineEdit);
      layout->addRow("Surname", new QLineEdit(patient["surname"]));
      window->setLayout(layout);
      scrollArea->setWidget(window);
      _layout3->addWidget(window);......@

      Can't anybody help me????

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cincirin
        wrote on last edited by
        #3

        I think "image viewer":http://developer.qt.nokia.com/doc/qt-4.8/widgets-imageviewer.html is good example of how to use QScrollArea providing a scrolling view around another widget (in your case window object)

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kanakas
          wrote on last edited by
          #4

          i need little more help please

          @layout = new QFormLayout;
          QToolBar *toolBar = new QToolBar(this);
          QSignalMapper *mapper = new QSignalMapper(this);
          pagesWidget = new QStackedWidget(this);

          homeButton = new QToolButton(this);
          page2Button = new QToolButton(this);

              firstPageWidget = new QWidget(this);
              secondPageWidget = new QWidget(this);
              thirdPageWidget = new QWidget(this);
          

          _layout1 = new QVBoxLayout(this);
          _layout2 = new QVBoxLayout(this);
          _layout3 = new QVBoxLayout(this);

              _layout2->addWidget(label2);
              _layout3->addWidget(label3);
          
              scrollArea = new QScrollArea(this);
              scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
              scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
              scrollArea->setWidgetResizable(true);
          

          scrollArea->setBackgroundRole(QPalette::Dark);
          scrollArea->setWidget(thirdPageWidget);

          firstPageWidget ->setLayout(_layout1);
          secondPageWidget ->setLayout(_layout2);
          thirdPageWidget ->setLayout(_layout3);

              pagesWidget->addWidget(firstPageWidget);
              pagesWidget->addWidget(secondPageWidget);
              pagesWidget->addWidget(thirdPageWidget);
              ….
              connect(mapper, SIGNAL(mapped(int)), pagesWidget, SLOT(setCurrentIndex(int)));
              setCentralWidget(pagesWidget);        
          }
          

          @

          I want scrollbars only at thirdPage with _layout3, but the scrollbars are visible in all pages and they aren't at the right position. They are displayed at the left top of the window.
          what can i do?

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kanakas
            wrote on last edited by
            #5

            thanks for nothing

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #6

              [quote author="kanakas" date="1329115726"]thanks for nothing[/quote]

              Yelling at volunteer fellow developers will surely make them eager to answer your questions immediately....

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • C Offline
                C Offline
                cincirin
                wrote on last edited by
                #7

                @

                QWidget* firstPageWidget = new QWidget;
                QVBoxLayout* firstLayout = new QVBoxLayout(firstPageWidget);
                firstLayout->addWidget(new QLabel(tr("First widget ..."), firstPageWidget));
                
                QWidget* secondPageWidget = new QWidget;
                QVBoxLayout* secondLayout = new QVBoxLayout(secondPageWidget);
                secondLayout->addWidget(new QLabel(tr("Second widget ..."), secondPageWidget));
                
                QWidget* thirdPageWidget = new QWidget;
                thirdPageWidget->resize(2400, 2400);
                QVBoxLayout* thirdLayout = new QVBoxLayout(thirdPageWidget);
                thirdLayout->addWidget(new QLabel(tr("Third widget ..."), thirdPageWidget));
                QScrollArea* scrollThirdWidget = new QScrollArea;
                scrollThirdWidget->setWidget(thirdPageWidget);
                
                QStackedWidget* stackedWidget = new QStackedWidget;
                stackedWidget->addWidget(firstPageWidget);
                stackedWidget->addWidget(secondPageWidget);
                stackedWidget->addWidget(scrollThirdWidget);
                
                QVBoxLayout *layout = new QVBoxLayout;
                layout->addWidget(stackedWidget);
                
                stackedWidget->setCurrentIndex(2);
                setCentralWidget(stackedWidget);
                

                @

                You'll see the scroll bars only in third page. If you scroll the window you'll see "Third widget..." text label.
                If you change the line 24, to setCurrentIndex(0) or setCurrentindex(1) the scroll bars are not visible and you'll see the "First widget ..." or "Second widget ..." text labels always visible on first or second page.

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  kanakas
                  wrote on last edited by
                  #8

                  thank you very much!!

                  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