Results 1 to 5 of 5

Thread: Add widget to Scroll area widget contents

  1. #1
    Join Date
    Mar 2013
    Posts
    43
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Add widget to Scroll area widget contents

    I have QWidget in QScrollArea. I have one push button in the MainWindow. I want to add QWidgets dynamically to the exixsting QWidget on pushbutton clicked. Please help me.

    Mythili

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Add widget to Scroll area widget contents

    Set a layout on the QWidget (the one in QScrollArea), and add the new dynamic widgets to the layout in a slot connected the QPushButton signal clicked()
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Mar 2013
    Posts
    43
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Add widget to Scroll area widget contents

    Thank u very much. Its working. I want to perform the same functions which i am doing for first QWidget which is created using ui. That functions are in seperate .cpp file.
    Now I am ading this dynamic widgets in mainwindow. How to perform those functions after creating QWidget dynamically in click event.

    Please help me.

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Add widget to Scroll area widget contents

    Make those functions a slots and connect to the button click signal (not event)
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  5. #5
    Join Date
    Oct 2012
    Location
    The land of pain (NY)
    Posts
    99
    Thanks
    7
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Windows Android

    Default Re: Add widget to Scroll area widget contents

    Quote Originally Posted by Santosh Reddy View Post
    Set a layout on the QWidget (the one in QScrollArea), and add the new dynamic widgets to the layout in a slot connected the QPushButton signal clicked()
    Hi Santosh.

    I only get one widget in the scroll area rather than multiple ones for every instance:

    void MainWindow:n_actionFile_triggered()
    {
    QTime t = QTime::currentTime();
    ctls = new Controls();
    connect(this, SIGNAL(UpdateInfo(int)), ctls, SLOT(WriteInfoNumber(int)));
    ui->scrollArea->setWidget(ctls);
    emit UpdateInfo(t.msecsSinceStartOfDay());
    }
    Controls is just a row of label, progressbar and checkbox. The signal emitted updates the label. As I said, there is only one row for every call of the method. The layout is made in the designer.
    Last edited by astodolski; 16th February 2014 at 20:02. Reason: More info

Similar Threads

  1. Replies: 8
    Last Post: 2nd February 2012, 19:52
  2. Scroll bars in scroll area not comming in scroll area
    By aurora in forum Qt Programming
    Replies: 3
    Last Post: 4th January 2012, 06:50
  3. Growing the contents of a scroll area.
    By spraff in forum Qt Programming
    Replies: 1
    Last Post: 2nd July 2009, 15:20
  4. Draw contents of widget in another widget
    By gustavosbarreto in forum Qt Programming
    Replies: 1
    Last Post: 6th August 2007, 14:43
  5. QRubberBand painting in the scroll area widget
    By SkripT in forum Qt Programming
    Replies: 7
    Last Post: 17th January 2006, 16:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.