Results 1 to 5 of 5

Thread: How to add the text items directly to the QListWidget on the "run time"?

  1. #1
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default How to add the text items directly to the QListWidget on the "run time"?

    How to add the text items directly to the QListWidget on the "run time"?

    Is there a way to do it?

  2. #2
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: How to add the text items directly to the QListWidget on the "run time"?

    See QListWidget Class Reference in Qt docs. The following methods should help you:

    void addItem ( const QString & label )
    void addItem ( QListWidgetItem * item )
    void addItems ( const QStringList & labels )

  3. #3
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default Re: How to add the text items directly to the QListWidget on the "run time"?

    Thanks, I had seen those functions before too, but is it possible to use them of "run time"?

    I mean, the addItem function "receives" text then pushes it in the list? But, I want to directly start typing in the list box.

  4. #4
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: How to add the text items directly to the QListWidget on the "run time"?


  5. The following user says thank you to mentalmushroom for this useful post:

    TheIndependentAquarius (23rd February 2012)

  6. #5
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default Re: How to add the text items directly to the QListWidget on the "run time"?

    That was indeed extremely helpful for "editing" the text on the fly.

    Here is what I did exactly:
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication app (argc, argv);
    4. QMainWindow *window = new QMainWindow ();
    5. QWidget *centralWidget = new QWidget (window);
    6.  
    7. QListWidget *genericTodoList = new QListWidget (window);
    8. genericTodoList->setFixedSize (445, 445);
    9.  
    10. QListWidgetItem *defaultText = new QListWidgetItem ("Double click here to compose the task");
    11. defaultText->setFlags (defaultText->flags () | Qt::ItemIsEditable);
    12. genericTodoList->insertItem (0, defaultText);
    13.  
    14.  
    15. QGridLayout *layout = new QGridLayout();
    16. centralWidget->setLayout (layout);
    17. layout->addWidget (genericTodoList, 0, 0);
    18.  
    19. window->setCentralWidget (centralWidget);
    20. window->show();
    21. return app.exec();
    22. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 3
    Last Post: 8th December 2011, 19:21
  2. Replies: 0
    Last Post: 15th April 2011, 19:04
  3. run time error "driver not loaded" for sqlite.
    By netmat in forum Qt Programming
    Replies: 0
    Last Post: 2nd August 2010, 05:42
  4. Replies: 4
    Last Post: 5th March 2010, 18:03
  5. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05

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.