Results 1 to 3 of 3

Thread: ScrollBar not working in the QScrollArea

  1. #1
    Join Date
    Nov 2014
    Posts
    54
    Thanks
    5
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default ScrollBar not working in the QScrollArea

    fact.h
    Qt Code:
    1. #ifndef FACTORYMENU_H
    2. #define FACTORYMENU_H
    3.  
    4. #include <QDialog>
    5. #include <QScrollArea>
    6. #include <QScrollBar>
    7. #include <QVBoxLayout>
    8. #include <QHBoxLayout>
    9. #include <QGridLayout>
    10.  
    11. namespace Ui {
    12. class FactoryMenu;
    13. }
    14.  
    15. class FactoryMenu : public QDialog
    16. {
    17. Q_OBJECT
    18.  
    19. public:
    20. explicit FactoryMenu(QWidget *parent = 0);
    21. ~FactoryMenu();
    22.  
    23. private:
    24. Ui::FactoryMenu *ui;
    25. QScrollArea *itemsArea;
    26. QGridLayout *layout;
    27. QVBoxLayout *printerLayout;
    28. QVBoxLayout *lcdLayout;
    29. QVBoxLayout *gsm_gprsLayout;
    30. QVBoxLayout *ifdLayout;
    31. QVBoxLayout *samLayout;
    32. QHBoxLayout *mainLayout;
    33. };
    34.  
    35. #endif // FACTORYMENU_H
    To copy to clipboard, switch view to plain text mode 
    fact.cpp
    Qt Code:
    1. #include "factorymenu.h"
    2. #include "ui_factorymenu.h"
    3.  
    4. FactoryMenu::FactoryMenu(QWidget *parent) :
    5. QDialog(parent),
    6. ui(new Ui::FactoryMenu)
    7. {
    8. ui->setupUi(this);
    9. QFrame::WinPanel;
    10. setWindowFlags(Qt::FramelessWindowHint);
    11.  
    12. ui->checkBox->setFixedSize(3000,150);
    13. ui->checkBox_2->setFixedSize(50,50);
    14. ui->checkBox_3->setFixedSize(50,50);
    15. ui->checkBox_4->setFixedSize(50,50);
    16. ui->checkBox_5->setFixedSize(50,50);
    17. ui->checkBox_6->setFixedSize(50,50);
    18. ui->checkBox_7->setFixedSize(50,50);
    19. ui->checkBox_8->setFixedSize(50,50);
    20. ui->checkBox_9->setFixedSize(50,50);
    21. ui->checkBox_10->setFixedSize(50,50);
    22. ui->checkBox_11->setFixedSize(50,50);
    23. ui->checkBox_12->setFixedSize(50,50);
    24.  
    25. mainLayout = new QHBoxLayout(ui->scrollWidget);
    26. mainLayout->addWidget(ui->checkBox);
    27. mainLayout->addWidget(ui->checkBox_2);
    28. mainLayout->addWidget(ui->checkBox_3);
    29. mainLayout->addWidget(ui->checkBox_4);
    30. mainLayout->addWidget(ui->checkBox_5);
    31. mainLayout->addWidget(ui->checkBox_6);
    32. mainLayout->addWidget(ui->checkBox_7);
    33. mainLayout->addWidget(ui->checkBox_8);
    34. mainLayout->addWidget(ui->checkBox_9);
    35. mainLayout->addWidget(ui->checkBox_10);
    36. mainLayout->addWidget(ui->checkBox_11);
    37. mainLayout->addWidget(ui->checkBox_12);
    38.  
    39. // printerLayout->addWidget(ui->checkBox);
    40. // mainLayout->addLayout(printerLayout);
    41. // mainLayout->addLayout(lcdLayout);
    42. // mainLayout->addLayout(gsm_gprsLayout);
    43. // mainLayout->addLayout(ifdLayout);
    44. // mainLayout->addLayout(samLayout);
    45.  
    46. itemsArea = new QScrollArea(this);
    47. itemsArea->setFocusPolicy(Qt::NoFocus);
    48. itemsArea->setWidget(ui->scrollWidget);
    49. itemsArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    50. itemsArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    51. // itemsArea->horizontalScrollBar()->setStyleSheet("width: 30px;");
    52. // itemsArea->verticalScrollBar()->setStyleSheet("width: 30px;");
    53. itemsArea->setGeometry(5,20,0,0);
    54. // itemsArea->setFixedSize(695,421);
    55. itemsArea->setFixedSize(670,411);
    56. itemsArea->setLayout(mainLayout);
    57. itemsArea->setStyleSheet(
    58. "QScrollArea {"
    59. "border: 2px solid;"
    60. "border-radius: 5px;"
    61. "Text-align:center;"
    62. "background-color:;""}");
    63. // itemsArea->setStyleSheet("background-image: url(:/images/menu_bg.jpg)");
    64.  
    65. }
    66.  
    67. FactoryMenu::~FactoryMenu()
    68. {
    69. delete ui;
    70. }
    To copy to clipboard, switch view to plain text mode 

    Hi i am trying to add around 100 checkboxes to my GUI for the i am trying to use the QScrollArea using the QHBOXLayout
    the GUI is showing fine but where as the scrolls are not working
    The screen shot of my GUI is also uploaded
    Here is my code can any one please where the bug is present
    Thanks in advance
    Rohith.G

    Attachment 11680

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: ScrollBar not working in the QScrollArea

    The scroll area doesn't seem to be in a layout.

    In any case, your actual code won't have the checkboxes in the "ui" part, since you are not going to do 100 of them manually.

    So my suggestion would be to change that into the actual code right away
    1) Add the scroll area to the dialog in Designer, properly layouted
    2) Create a QWidget derived class and in its constructor create the checkboxes and put the into the widget's layout
    3) In the dialog's constructor create an instance of that class and put it into the scroll area

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    gunturrohith (12th February 2016)

  4. #3
    Join Date
    Nov 2014
    Posts
    54
    Thanks
    5
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: ScrollBar not working in the QScrollArea

    Thanks It helped me a lot

Similar Threads

  1. Replies: 0
    Last Post: 4th August 2015, 10:12
  2. QScrollarea events transferring to scrollbar
    By babu198649 in forum Qt Programming
    Replies: 15
    Last Post: 6th September 2013, 23:33
  3. ScrollBar position for QScrollArea
    By Dendy in forum Qt Programming
    Replies: 7
    Last Post: 28th March 2011, 12:34
  4. Replies: 1
    Last Post: 9th February 2010, 16:04
  5. why scrollbar doesn't display in QscrollArea
    By myhot21 in forum Qt Programming
    Replies: 2
    Last Post: 23rd July 2009, 03:38

Tags for this Thread

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.