Results 1 to 18 of 18

Thread: How to present data in a list

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Join Date
    Oct 2010
    Posts
    55
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    1
    Thanked 11 Times in 10 Posts
    Wiki edits
    9

    Default Re: How to present data in a list

    Something like...

    mainwindow.h:
    Qt Code:
    1. #include <QtGui/QMainWindow>
    2.  
    3. class QLineEdit;
    4.  
    5. class MainWindow : public QMainWindow
    6. {
    7. Q_OBJECT
    8.  
    9. public:
    10. MainWindow(QWidget *parent = 0);
    11. ~MainWindow();
    12.  
    13. protected slots:
    14. void addItemToList();
    15.  
    16. private:
    17. QLineEdit *m_edit;
    18. QListWidget *m_list;
    19. };
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp:
    Qt Code:
    1. #include <QListWidget>
    2. #include <QLineEdit>
    3. #include <QVBoxLayout>
    4. #include "mainwindow.h"
    5.  
    6. MainWindow::MainWindow(QWidget *parent)
    7. : QMainWindow(parent),
    8. m_edit(new QLineEdit),
    9. m_list(new QListWidget)
    10. {
    11. QWidget *widget = new QWidget;
    12. QVBoxLayout *layout = new QVBoxLayout;
    13. layout->addWidget(m_list);
    14. layout->addWidget(m_edit);
    15. widget->setLayout(layout);
    16. setCentralWidget(widget);
    17.  
    18. QObject::connect(m_edit, SIGNAL(returnPressed()),
    19. this, SLOT(addItemToList()));
    20. }
    21.  
    22. MainWindow::~MainWindow()
    23. {
    24. }
    25.  
    26. void MainWindow::addItemToList()
    27. {
    28. m_list->addItem(m_edit->text());
    29. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by helloworld; 1st April 2011 at 23:05.

Similar Threads

  1. How to postpone a signal until present form is closed ?
    By marcvanriet in forum Qt Programming
    Replies: 6
    Last Post: 15th December 2010, 13:22
  2. Replies: 3
    Last Post: 23rd November 2009, 14:41
  3. How to map tree model data to list view
    By msopanen in forum Qt Programming
    Replies: 0
    Last Post: 10th November 2009, 20:56
  4. question about present a picture using QPixmap
    By lovelypp in forum Qt Programming
    Replies: 2
    Last Post: 12th July 2008, 16:43
  5. QFtp->List() does not recieve any data
    By nopalot in forum Qt Programming
    Replies: 5
    Last Post: 17th May 2006, 21:42

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
  •  
Qt is a trademark of The Qt Company.