Results 1 to 16 of 16

Thread: I want to create a form with QListView

  1. #1
    Join Date
    May 2010
    Location
    China
    Posts
    66
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Smile I want to create a form with QListView

    i want to create a listview as the attachement,but i can't find any sample code ,could any one can help me

    未命名..jpg

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: I want to create a form with QListView

    Have a look at QListView::setViewModeJust play in designer a little.

  3. #3
    Join Date
    May 2010
    Location
    China
    Posts
    66
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: I want to create a form with QListView

    i can't get how to use it ,can you give me some sample code from the beginning to end ,thank you

  4. #4
    Join Date
    Jul 2009
    Posts
    139
    Thanks
    13
    Thanked 59 Times in 52 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: I want to create a form with QListView

    Qt Code:
    1. #include <QtGui>
    2. int main(int argc, char * argv[])
    3. {
    4. QApplication a(argc, argv);
    5.  
    6. QListView * lv = new QListView(0);
    7.  
    8. model->setData(model->index(0, 0), lv->style()->standardIcon(QStyle::SP_BrowserReload), Qt::DecorationRole);
    9. model->setData(model->index(0, 0), "Hello World!", Qt::DisplayRole);
    10.  
    11. model->setData(model->index(1, 0), lv->style()->standardIcon(QStyle::SP_FileIcon), Qt::DecorationRole);
    12. model->setData(model->index(1, 0), "Goodbye World!", Qt::DisplayRole);
    13.  
    14. lv->setViewMode(QListView::IconMode);
    15. lv->setModel(model);
    16. lv->show();
    17.  
    18. return a.exec();
    19. }
    To copy to clipboard, switch view to plain text mode 

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

    xiongxiongchuan (3rd June 2010)

  6. #5
    Join Date
    May 2010
    Location
    China
    Posts
    66
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: I want to create a form with QListView

    Thanks ,you are so kind ,but when i do this as you taught me ,and i found the lable is editable ,how to set the label is not allowed to be edited;

  7. #6
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: I want to create a form with QListView

    Ohh come one, read the documentation
    http://doc.qt.nokia.com/4.6/index.html

  8. #7
    Join Date
    May 2010
    Location
    China
    Posts
    66
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: I want to create a form with QListView

    i have looked up for this problem in the QT Document ,but i can't find any solutions ,plz help me

  9. #8
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: I want to create a form with QListView

    What label?

  10. #9
    Join Date
    Jul 2009
    Posts
    139
    Thanks
    13
    Thanked 59 Times in 52 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: I want to create a form with QListView

    You have to set the item flags, as needed:
    Qt Code:
    1. model->item(0,0)->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
    To copy to clipboard, switch view to plain text mode 

  11. #10
    Join Date
    May 2010
    Location
    China
    Posts
    66
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: I want to create a form with QListView

    i set the lable model as this below ,however ,the lable still can be edit,i can't find any properties to stop this!

    when i double clicked the item ,the lable can be renamed
    Qt Code:
    1. model->setData(model->index(0,0),tr("This is input well data file"),Qt::WhatsThisRole| Qt::ItemIsEditable);
    To copy to clipboard, switch view to plain text mode 
    Last edited by xiongxiongchuan; 5th June 2010 at 12:50.

  12. #11
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: I want to create a form with QListView

    If you dont want the item editable, shouldnt you be using NOT of Qt::ItemIsEditable ( ~Qt::ItemIsEditable)

  13. #12
    Join Date
    May 2010
    Location
    China
    Posts
    66
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: I want to create a form with QListView

    Qt Code:
    1. model->setData(model->index(0, 0), tr("Well Data"), Qt::DisplayRole|~Qt::ItemIsEditable);
    To copy to clipboard, switch view to plain text mode 
    i using the code as this ,however,it did't display the lable ,and still can be edited

  14. #13
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    474
    Thanks
    10
    Thanked 62 Times in 60 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: I want to create a form with QListView

    You have to set flags, not data.

    Ginsengelf

  15. #14
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: I want to create a form with QListView

    As far as I remember, I guess the flags are stored in standard item with (Qt::UserRole - 1)

  16. #15
    Join Date
    May 2010
    Location
    China
    Posts
    66
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: I want to create a form with QListView

    could you give me some more details ,thanks !

  17. #16
    Join Date
    Jun 2010
    Location
    Salatiga, Indonesia
    Posts
    160
    Thanks
    11
    Thanked 32 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    1

    Default Re: I want to create a form with QListView

    try this code:

    Qt Code:
    1. yourListView->setEditTriggers(QAbstractItemView::NoEditTriggers);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 5
    Last Post: 12th March 2010, 21:43
  2. Help me to load one form over another form PushButton
    By wagmare in forum Qt Programming
    Replies: 7
    Last Post: 26th November 2008, 16:11
  3. Hiding a form and opening another form
    By anafor2004 in forum Newbie
    Replies: 1
    Last Post: 20th February 2008, 15:04
  4. Help! Trying to create a ui form and use it
    By pmabie in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2007, 19:43
  5. How to create an Insert/Submit button for a form.
    By fnmblot in forum Qt Programming
    Replies: 5
    Last Post: 4th August 2006, 16:18

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.