Results 1 to 3 of 3

Thread: QScrollArea not showing

  1. #1
    Join Date
    Jun 2010
    Posts
    97
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QScrollArea not showing

    Hi,

    I have written following code. But it is now show scroll bars and also not scrolling. I want to use scroll area and add widget to that.


    Qt Code:
    1. #include "files.h"
    2. Files::Files(QWidget *parent) :QWidget(parent)
    3. {
    4. generateForm();
    5. }
    6.  
    7.  
    8. void Files::generateForm()
    9. {
    10. QScrollArea *scroll = new QScrollArea;
    11. QWidget *wid = new QWidget;
    12. QGridLayout *lay = new QGridLayout(wid);
    13. QLabel *lb_file_id = new QLabel("FILE_ID");
    14. lay->addWidget(lb_file_id,0,0);
    15. QLineEdit *tx_file_id = new QLineEdit();
    16. lay->addWidget(tx_file_id,0,1,1,1);
    17. QLabel *lb_file_name = new QLabel("FILE_NAME");
    18. lay->addWidget(lb_file_name,0,2);
    19. QLineEdit *tx_file_name = new QLineEdit();
    20. lay->addWidget(tx_file_name,0,3,1,1);
    21. QLabel *lb_file_type = new QLabel("FILE_TYPE");
    22. lay->addWidget(lb_file_type,1,0);
    23. QLineEdit *tx_file_type = new QLineEdit();
    24. lay->addWidget(tx_file_type,1,1,1,1);
    25.  
    26. tx_extra->setMinimumHeight(300);
    27. QSpacerItem *spacer = new QSpacerItem(5,5,QSizePolicy::Expanding,QSizePolicy::Expanding);
    28. lay->addItem(spacer,37,2);
    29.  
    30. QHBoxLayout *hb1 = new QHBoxLayout(scroll);
    31. hb1->addWidget(wid);
    32. scroll->setWidget(wid);
    33. scroll->setWidgetResizable(true);
    34. QHBoxLayout *hb2 = new QHBoxLayout();
    35. hb2->addWidget(scroll);
    36. setLayout(hb2);
    37. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QScrollArea not showing

    Lines 30 and 31 surely make no sense, remove them. Also I don't see any points for lines 27 and 28, you can remove them too. See if it helps. Of course the internal widget needs to be large enough to make scroll bars appear.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2010
    Posts
    97
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QScrollArea not showing

    Following code worked.

    Qt Code:
    1. #include "mysample.h"
    2.  
    3. MySample::MySample(QWidget *parent) :
    4. QWidget(parent)
    5. {
    6. QWidget *wid = new QWidget;
    7. QGridLayout *gridLay = new QGridLayout(wid);
    8.  
    9. int col=0;
    10. int row=0;
    11. for(int i=0; i<100; i++){
    12. QLabel *lb = new QLabel("Label "+QString::number(i));
    13. gridLay->addWidget(lb,row,col);
    14. col++;
    15. if (col==4){
    16. col=0;
    17. row++;
    18. }
    19. QLineEdit *tx = new QLineEdit;
    20. gridLay->addWidget(tx,row,col);
    21. col++;
    22. if (col==4){
    23. col=0;
    24. row++;
    25. }
    26. }
    27. QScrollArea *scroll = new QScrollArea;
    28. wid->setBackgroundRole(QPalette::Dark);
    29. scroll->setWidgetResizable(true);
    30. QHBoxLayout *hb1 = new QHBoxLayout();
    31. scroll->setLayout(hb1);
    32. scroll->setWidget(wid);
    33.  
    34. hb2->addWidget(scroll);
    35. setLayout(hb2);
    36.  
    37. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 0
    Last Post: 11th August 2010, 10:02
  2. Replies: 2
    Last Post: 10th March 2008, 20:16
  3. QScrollArea ?
    By whitefurrows in forum Qt Programming
    Replies: 2
    Last Post: 27th July 2007, 22:15
  4. QScrollArea
    By merry in forum Qt Programming
    Replies: 12
    Last Post: 20th June 2007, 13:05
  5. Showing QMainWindow without showing a child QWidget
    By discostu in forum Qt Programming
    Replies: 3
    Last Post: 4th March 2007, 09:03

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.