Results 1 to 3 of 3

Thread: why scrollbar doesn't display in QscrollArea

  1. #1
    Join Date
    May 2009
    Posts
    4
    Thanks
    1

    Unhappy why scrollbar doesn't display in QscrollArea

    i add Multiple QListwidget to QscrollArea,but the scrollbar doesn't display in QscrollArea, why?


    Qt Code:
    1. #include "mainwindow.h"
    2.  
    3. MainWindow::MainWindow(QWidget *parent)
    4. : QMainWindow(parent)
    5. {
    6. rightLayout = new QVBoxLayout;
    7. QWidget *widget = new QWidget;
    8. widget->setLayout(rightLayout);
    9. widget->setMinimumHeight(100);
    10. widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    11.  
    12. QScrollArea *scroll = new QScrollArea;
    13. scroll->setWidget(widget);
    14. scroll->setWidgetResizable(true);
    15. splitter = new QSplitter;
    16. QPushButton *button = new QPushButton;
    17. button->setText("Add Widget");
    18. button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    19. splitter->addWidget(button);
    20.  
    21. splitter->addWidget(scroll);
    22.  
    23. QObject::connect(button, SIGNAL( clicked() ), this, SLOT(addMyWidget()));
    24.  
    25.  
    26. this->setCentralWidget(splitter);
    27. }
    28. void MainWindow::addMyWidget()
    29. {
    30. QListWidget *listWidget = new QListWidget;
    31. for(int i = 0; i < 4; i++)
    32. {
    33. newItem->setText("aaaaaa");
    34. listWidget->addItem(newItem);
    35. }
    36.  
    37. listWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    38. rightLayout->addWidget(listWidget);
    39. }
    40.  
    41. MainWindow::~MainWindow()
    42. {
    43.  
    44. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images
    • File Type: jpg 1.jpg (7.5 KB, 33 views)
    • File Type: jpg 2.jpg (9.6 KB, 28 views)
    Last edited by wysota; 22nd July 2009 at 20:50. Reason: Changed [quote] to [code]

  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: why scrollbar doesn't display in QscrollArea

    Set the vertical size policy of the widget you place into the scroll area to Minimum. Same goes for the list widgets you place into it.
    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. The following user says thank you to wysota for this useful post:

    myhot21 (23rd July 2009)

  4. #3
    Join Date
    May 2009
    Posts
    4
    Thanks
    1

    Default Re: why scrollbar doesn't display in QscrollArea

    Quote Originally Posted by wysota View Post
    Set the vertical size policy of the widget you place into the scroll area to Minimum. Same goes for the list widgets you place into it.
    thank you!

Similar Threads

  1. QScrollarea events transferring to scrollbar
    By babu198649 in forum Qt Programming
    Replies: 15
    Last Post: 6th September 2013, 23:33
  2. Replies: 1
    Last Post: 13th September 2008, 12:00
  3. Display only PNG image on desktop
    By durbrak in forum Qt Programming
    Replies: 32
    Last Post: 15th March 2008, 22:55
  4. GraphicsView/GraphicsScene: scrollbar policy Qt::ScrollBarAsNeeded
    By Pieter from Belgium in forum Qt Programming
    Replies: 4
    Last Post: 21st March 2007, 14:15
  5. QScrollArea display custom QLabel
    By spawnwj in forum Qt Programming
    Replies: 6
    Last Post: 6th December 2006, 04:38

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.