Results 1 to 5 of 5

Thread: How to display many widgets in grid?

  1. #1
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default How to display many widgets in grid?

    I want to display many widgets in colums and rows(shows as picture),I will not use tablewidget?how to relized it?Thank you.22.png

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to display many widgets in grid?


  3. #3
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to display many widgets in grid?

    Can QGridLayout draw the grid lines(show as picture ,blue lines) between the Label and Textline?

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to display many widgets in grid?

    Can QGridLayout draw the grid lines
    No. QGridLayout is a layout, not a widget. It has no visual appearance.

    I think you will probably have to write your own class, based on QWidget, to do this. You could also use the Qt Graphics View Framework, but either way, the amount of work is about the same.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to display many widgets in grid?

    This may scratch your itch depending on how fussy you are about the lines.
    Qt Code:
    1. #include "widget.h"
    2.  
    3. #include <QGridLayout>
    4. #include <QVBoxLayout>
    5. #include <QFrame>
    6. #include <QLabel>
    7. #include <QLineEdit>
    8.  
    9. Widget::Widget(QWidget *parent)
    10. : QWidget(parent)
    11. {
    12. setStyleSheet(
    13. QStringLiteral(
    14. "QFrame { border: 1px solid blue; } "
    15. "QLabel, QLineEdit { padding: 5px; border: 1px solid blue; } "
    16. )
    17. );
    18. QVBoxLayout *layout = new QVBoxLayout(this);
    19. QFrame *frame = new QFrame(this);
    20. layout->addWidget(frame);
    21.  
    22. QGridLayout *gridLayout = new QGridLayout(frame);
    23. gridLayout->setSpacing(0);
    24. gridLayout->setMargin(0);
    25.  
    26. for (int row = 0; row < 4; ++row) {
    27. QLabel *label = new QLabel(QString("Row %1").arg(row), this);
    28. QLineEdit *edit = new QLineEdit(this);
    29. gridLayout->addWidget(label, row, 0);
    30. gridLayout->addWidget(edit, row, 1);
    31. }
    32. }
    33.  
    34. Widget::~Widget()
    35. {
    36. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 2
    Last Post: 4th September 2014, 12:09
  2. Replies: 0
    Last Post: 30th April 2012, 16:17
  3. Problem in layout widgets in a grid
    By franco.amato in forum Newbie
    Replies: 31
    Last Post: 24th November 2010, 23:22
  4. Custom widgets in a grid view
    By ada10 in forum Newbie
    Replies: 2
    Last Post: 23rd August 2010, 12:28
  5. Display Grid
    By vinod sharma in forum Qt Programming
    Replies: 0
    Last Post: 8th April 2010, 06:59

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.