×

Discussion Board

Page 1 of 3 123 LastLast
Results 1 to 15 of 31

Thread: Scrolling in qt

  1. #1
    Regular Contributor
    Join Date
    Jan 2011
    Posts
    100

    Scrolling in qt

    Hello
    My UI consists of many widgets so i want to add scrolling functionality to my form. I used scollarea but its not working..how can i achieve it using UI designer ?!
    Please help.

  2. #2
    Registered User
    Join Date
    Feb 2010
    Posts
    210

    Re: Scrolling in qt

    Be sure you set the focus policy of all your widgets under the properties section in designer to allow scrolling to them.
    Cheers,
    Jon

  3. #3
    Regular Contributor
    Join Date
    Jan 2011
    Posts
    100

    Re: Scrolling in qt

    Yes I enabled focus policy property ..but still it didnt work !
    -Amruta

  4. #4
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: Scrolling in qt

    try something like this
    Code:
    	QListWidget *list0 = new QListWidget;
    	    for (int i = 0; i < 5; ++i) {
    	        list0->addItem(QString("List_1 %1").arg(i));
    	    }
    
    	
    	QListWidget *list1 = new QListWidget;
    	    for (int i = 0; i < 5; ++i) {
    	        list1->addItem(QString("List_1 %1").arg(i));
    	    }
    	
    	QListWidget *list2 = new QListWidget;
    	    for (int i = 0; i < 5; ++i) {
    	        list2->addItem(QString("List_2 %1").arg(i));
    	    }
    	
    	QListWidget* list3 = new QListWidget;
    	for(int i = 0;i<10;++i)
    		{
    		list3->addItem(QString("List_3 %1").arg(i));
    		}
    
    	
    	 QLabel *imageLabel = new QLabel(this);
    	 imageLabel->setText("This is my Label");
    	 imageLabel->move(QPoint(0,0));
    	 QHBoxLayout* lay=new QHBoxLayout(this);
    	 list2->setGeometry(QRect(20,20,200,200));
    	 QVBoxLayout *vbox = new QVBoxLayout;
    	 vbox->addWidget(imageLabel);
    	 vbox->addWidget(list0);
    	 vbox->addWidget(list1);
    	 vbox->addWidget(list2);
    	 vbox->addWidget(list3);
    	 
         
    	 QWidget* mainWidget = new QWidget();
    	 mainWidget->setLayout(vbox);
    	 
    	 QScrollArea* scrollArea = new QScrollArea(this);
    	 scrollArea->setWidgetResizable(true);
    	 scrollArea->setBackgroundRole(QPalette::Light);
    	 scrollArea->setWidget(mainWidget);
    	 
    	 
    	 lay->addWidget(scrollArea);
    	 setLayout(lay);
    this will give you a idea of using QScrollArea in your application i use it inside the constructor of a class derived from QWidget.

  5. #5
    Regular Contributor
    Join Date
    Jan 2011
    Posts
    100

    Re: Scrolling in qt

    Thanks for the code..but can you help how to achieve same using UI designer..i want to use deisgner for the same.

    -Amruta

  6. #6
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: Scrolling in qt

    sorry but never tried using QScrollArea using the ui designer you can try to implement the same logic and tell us if that works or not.

  7. #7
    Regular Contributor
    Join Date
    Jan 2011
    Posts
    100

    Re: Scrolling in qt

    I tried bt its couldnt scroll the window...!

    -Amruta

  8. #8
    Regular Contributor
    Join Date
    Jan 2011
    Posts
    100

    Re: Scrolling in qt

    This is my code:
    ui->setupUi(this);
    QRect q=QWidget::geometry();
    // ui->scrollArea->setGeometry(0,0,q.width(),q.height());
    QVBoxLayout *vbox = new QVBoxLayout;
    QLineEdit *line1=new QLineEdit;
    line1->setText("hi");
    line1->setFocus();

    QLineEdit *line2=new QLineEdit;
    line2->setText("hi");
    line2->setFocus();

    QLineEdit *line3=new QLineEdit;
    line3->setText("hi");
    line3->setFocus();

    vbox->addWidget(line1);
    vbox->addWidget(line2);
    vbox->addWidget(line3);

    this->setLayout(vbox);
    QWidget* mainWidget = new QWidget();
    mainWidget->setLayout(vbox);

    QScrollArea* scrollArea = new QScrollArea(this);
    scrollArea->setWidgetResizable(true);
    scrollArea->setBackgroundRole(QPalette::Light);
    //scrollArea->setGeometry(0,0,q.width(),q.height());
    scrollArea->setFocus();
    scrollArea->setWidget(mainWidget);
    Please tell me How to achieve scrolling of form in UI designer..

    -Amruta
    Last edited by amrutap27; 2011-02-26 at 07:36.

  9. #9
    Regular Contributor
    Join Date
    Jan 2011
    Posts
    100

    Failed to use QScrollArea

    Please tell me how can i achieve the same using UI designer ?
    -Amruta

  10. #10
    Nokia Developer Champion
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: set Several Widget in QScrollArea

    Drag a scroll area onto the canvas, drag a layout onto the scroll area, drag the desired widgets into the layout.

  11. #11
    Regular Contributor
    Join Date
    Jan 2011
    Posts
    100

    Re: set Several Widget in QScrollArea

    Thanks tried it..but how can I set it to size of the screen i used setGeometry() but lost scrolling effect ! I have 4 widgets but could see only 2 n couldnt scroll to see other widgets !
    -Amruta

  12. #12
    Registered User
    Join Date
    Feb 2010
    Posts
    210

    Re: Scrolling in qt

    It appears to me that you are trying to set the focus of multiple items at the same time, this would not be possible. Set the focus to the first item only and set the focus property of the rest to strongFocus and see if that works...
    Jon

  13. #13
    Nokia Developer Moderator
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Scrolling in qt

    Quote Originally Posted by amrutap27 View Post
    Please tell me How to achieve scrolling of form in UI designer..
    You add the scroll area to the window, then add layout to the area, then three line edits to the area.

  14. #14
    Nokia Developer Champion
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: set Several Widget in QScrollArea

    Well, first off I'd suggest that you read the documentation.

  15. #15
    Regular Contributor
    Join Date
    Jan 2011
    Posts
    100

    Re: Scrolling in qt

    Thanks !
    I had problem about setting scrollarea to the size of the screen i wrote a code:
    QRect q=QApplication::desktop()->screenGeometry(this);
    ui->scrollArea->setGeometry(0,0,(q.width()-10),(q.height()-30));

    -Amruta
    Last edited by amrutap27; 2011-02-27 at 18:07.

Similar Threads

  1. Easy kinetict scrolling with QT Creator
    By gerasalus in forum Qt
    Replies: 13
    Last Post: 2011-01-17, 19:33

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •