Results 1 to 5 of 5

Thread: Scrollable window

  1. #1
    Join Date
    Aug 2012
    Location
    Paris
    Posts
    15
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Scrollable window

    Dear Sirs,

    I'm designing a window which appears when information has to be entered.
    This window contains a variable number of ComboBox, but when this number is to big, the window size is bigger than the screen size.

    I tried to implement a scroll bar (last lines of the code bellow), but it freezes the program ??

    Would someone have any idea ?

    Thanks in advance,

    Best Regards,

    Stéphane


    Qt Code:
    1. // Telemetry data assignment
    2. void MainWindow::data_assignment()
    3. {
    4. // New window object instanciation
    5. window_data_assignment = new QWidget;
    6.  
    7. ...
    8. ...
    9. ...
    10. ...
    11.  
    12. // Data input assigment sub-widget creation
    13. QWidget *data_assigment_input;
    14. data_assigment_input = new QWidget;
    15.  
    16. // Label displayed of the combobox
    17. QLabel *Label;
    18. // Combo box // if column_number if a constant
    19. // QComboBox *ComboBox[columns_number];
    20.  
    21. // Combo box // if column_number if a constant
    22. // this will have to be release by using delete []comboBox;
    23. QComboBox** ComboBox = new QComboBox*[columns_number];
    24. // delete []comboBox;
    25.  
    26.  
    27. // GRID LAYOUT declaration
    28. QGridLayout *grid;
    29.  
    30.  
    31. // GRID LAYOUT INSTANTIATION
    32. grid = new QGridLayout;
    33.  
    34. // Data assigmnent window filling with input sub-widgets
    35. for (unsigned int row = 0; row < columns_number; row++)
    36. {
    37. Label = new QLabel(tr("Data type of column # ")+QString::number(row+1)+" :");
    38.  
    39. ComboBox[row] = new QComboBox;
    40.  
    41. // Combo box data filling
    42. for (unsigned int i = 0; i<DATA_TYPE_NB; i++)
    43. ComboBox[row]->addItem(tr(DATA_TYPE[i]));
    44.  
    45. grid->addWidget(Label, row, 0);
    46. grid->addWidget(ComboBox[row], row, 1);
    47. }
    48.  
    49. //
    50. data_assigment_input->setLayout(grid);
    51.  
    52.  
    53.  
    54. // Quit push button creation
    55. QPushButton *quit = new QPushButton(tr("OK"));
    56. // quit->setFont(QFont("Times", 18, QFont::Bold));
    57.  
    58. // Connection between widgets
    59. connect(quit, SIGNAL(clicked()), window_data_assignment, SLOT(close()));
    60.  
    61. // Size/Position auto-managment by QVBoxLayout
    62. QVBoxLayout *wlayout = new QVBoxLayout;
    63. wlayout->addWidget(data_assigment_input);
    64. wlayout->addWidget(quit);
    65.  
    66.  
    67.  
    68. // Window scrolling
    69. // Adding a scroll area
    70. QScrollArea *scrollArea = new QScrollArea;
    71. // scrollArea->setWidgetResizable(true);
    72. scrollArea->setWidget(window_data_assignment);
    73.  
    74. wlayout->addWidget(scrollArea);
    75.  
    76. window_data_assignment->setLayout(wlayout);
    77.  
    78. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Scrollable window

    Hi,

    see QScrollArea. It should solve your problem.

    Best,
    Lykurg

  3. #3
    Join Date
    Aug 2012
    Location
    Paris
    Posts
    15
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Scrollable window

    Dear Lykurg,

    Thank you very much for your answer !!!

    This is what I did with the following code (see bellow), but unfortunately without success :'(

    Best Regards,

    Stéphane

    68. // Window scrolling
    69. // Adding a scroll area
    70. QScrollArea *scrollArea = new QScrollArea;
    71. // scrollArea->setWidgetResizable(true);
    72. scrollArea->setWidget(window_data_assignment);
    73.
    74. wlayout->addWidget(scrollArea);
    75.
    76. window_data_assignment->setLayout(wlayout);

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Scrollable window

    Of course it does not work! Your code is nonsense.


    You assign window_data_assignment to the scroll area. That is fine. Then you add the scroll area to a layout. That is also fine, but then you add the layout to window_data_assignment... Why?

  5. #5
    Join Date
    Aug 2012
    Location
    Paris
    Posts
    15
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Scrollable window

    Thank you so much for your answer, and you are so right, sorry for this nonsense

    I managed to solve my problem, with the following code (sorry, I didn't find the 'insert code' button), thanks again for you help !!

    Best Regards,

    Stéphane


    // Global layout declaration (window_data_assignment)
    QVBoxLayout * vLayout = new QVBoxLayout(window_data_assignment);
    // ScrollArea declaration (window_data_assignment)
    QScrollArea * scrollArea = new QScrollArea(window_data_assignment);

    // ScrollArea properties definition
    scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded) ;
    scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeede d);
    scrollArea->setWidgetResizable(false);

    // Assigment of data_assigment_input to ScrollArea
    scrollArea->setWidget(data_assigment_input);

    // Assigment of ScrollArea to the global layout
    vLayout->addWidget(scrollArea);

    // Assigment of the global layout to the current window widget
    window_data_assignment->setLayout(vLayout);

Similar Threads

  1. Scrollable QMenu
    By MasterBLB in forum Qt Programming
    Replies: 0
    Last Post: 11th October 2010, 11:17
  2. Scrollable QLayout
    By Luc4 in forum Qt Programming
    Replies: 5
    Last Post: 2nd August 2010, 15:49
  3. Scrollable Panel
    By qtoptus in forum Qt Programming
    Replies: 1
    Last Post: 5th May 2010, 11:07
  4. Making the whole window/form scrollable
    By ike in forum Qt Tools
    Replies: 2
    Last Post: 6th October 2008, 20:24
  5. QStackedWidget scrollable
    By mattia in forum Qt Tools
    Replies: 1
    Last Post: 19th April 2008, 10:02

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.