Results 1 to 6 of 6

Thread: QListView: Custom or not

  1. #1
    Join Date
    Feb 2011
    Location
    Latvia
    Posts
    139
    Thanks
    24
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QListView: Custom or not

    I need to create a list of custom widgets (each widget contains 4 labels).
    Do i need to create some custom list model to achieve this?
    I've been reading docs for 2 hours, but i can't still get - what do i need to create that list of custom widgets. If someone could tell me the theory about what should i do (not the code, but the steps, example: create new project, create class called ListModel, where u need to write the new model for your list, because... and so on) I would really appreciate that.
    I need to tell you, that i have to do this using MVC...

  2. #2
    Join Date
    Feb 2011
    Location
    Latvia
    Posts
    139
    Thanks
    24
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListView: Custom or not

    So i think i'll need
    Qt Code:
    1. class ListModel : public QAbstractListModel
    To copy to clipboard, switch view to plain text mode 
    but the problem is - i still don't know how to implement it. I think I will need to pass an array to this model, which will create elements using that array.
    I don't know how to write that, right now i have this declaration:
    Qt Code:
    1. class ListModel : public QAbstractListModel
    2. {
    3. Q_OBJECT
    4. public:
    5. ListModel(const QString array[20][3], QObject *parent = 0)
    6. : QAbstractListModel(parent), str(array[20][3]){}
    7.  
    8. int rowCount(const QModelIndex &parent = QModelIndex()) const;
    9. QVariant data(const QModelIndex &index, int role) const;
    10.  
    11. private:
    12. QString str;
    13. };
    To copy to clipboard, switch view to plain text mode 

    But i cannot get to strings inside that array. In fact i don't think anything here is written right...
    Can someone tell me what?

  3. #3
    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: QListView: Custom or not

    One way you can have your custom widgets with 4 labels in a vertical layout.. it will give the feel of list.

    Second way is to use QListWidgetand delegates. Have a look at QStyledItemDelegateand QItemDelegate
    Also look at star rating example in Qt Demos

  4. #4
    Join Date
    Feb 2011
    Location
    Latvia
    Posts
    139
    Thanks
    24
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListView: Custom or not

    Where can i look at those Qt Demos?

  5. #5
    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: QListView: Custom or not

    If you have installed Qt, it must be in ur QTDIR/bin/qtdemo..

  6. #6
    Join Date
    Feb 2011
    Location
    Latvia
    Posts
    139
    Thanks
    24
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListView: Custom or not

    Hm... I have NokiaQtSdk, i found that qtdemo, but i cannot launch it...
    It throws many errors:
    Qt Code:
    1. WARNING: c:\NokiaQtSDK\Simulator\Qt\mingw\lib\qtmaind.prl:1: Unescaped backslashes are deprecated.
    2.  
    3. WARNING: c:\NokiaQtSDK\Simulator\Qt\mingw\lib\QtDeclaratived.prl:1: Unescaped backslashes are deprecated.
    4.  
    5. WARNING: c:\NokiaQtSDK\Simulator\Qt\mingw\lib\QtSqld.prl:1: Unescaped backslashes are deprecated.
    6.  
    7. WARNING: c:\NokiaQtSDK\Simulator\Qt\mingw\lib\QtXmld.prl:1: Unescaped backslashes are deprecated.
    8.  
    9. WARNING: c:\NokiaQtSDK\Simulator\Qt\mingw\lib\QtGuid.prl:1: Unescaped backslashes are deprecated.
    10.  
    11. WARNING: c:\NokiaQtSDK\Simulator\Qt\mingw\lib\QtNetworkd.prl:1: Unescaped backslashes are deprecated.
    12.  
    13. WARNING: c:\NokiaQtSDK\Simulator\Qt\mingw\lib\QtCored.prl:1: Unescaped backslashes are deprecated.
    14.  
    15. WARNING: c:\NokiaQtSDK\Simulator\Qt\mingw\lib\qtmaind.prl:1: Unescaped backslashes are deprecated.
    16.  
    17. WARNING: c:\NokiaQtSDK\Simulator\Qt\mingw\lib\qtmain.prl:1: Unescaped backslashes are deprecated.
    18.  
    19. WARNING: c:\NokiaQtSDK\Simulator\Qt\mingw\lib\QtDeclarative.prl:1: Unescaped backslashes are deprecated.
    20.  
    21. c:/nokiaqtsdk/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../../mingw32/bin/ld.exe: cannot find -lQtHelpd
    22.  
    23. collect2: ld returned 1 exit status
    24.  
    25. mingw32-make[1]: *** [..\..\bin\qtdemo.exe] Error 1
    26.  
    27. mingw32-make: *** [debug] Error 2
    28.  
    29. Процесс "C:/NokiaQtSDK/mingw/bin/mingw32-make.exe" завершился с кодом %2.
    30. Возникла ошибка при сборке проекта qtdemo (цель: Ð*мулятор Qt)
    31. Во время выполнения сборки на этапе "Сборка"
    To copy to clipboard, switch view to plain text mode 

    Maybe u could just copy the code from the example u told me to watch? I would really appreciated that...

Similar Threads

  1. QListView::setIndexWidget custom sorting
    By drus in forum Qt Programming
    Replies: 2
    Last Post: 10th December 2010, 08:52
  2. add custom widget items to QListView or QListWidget
    By yazwas in forum Qt Programming
    Replies: 2
    Last Post: 16th September 2010, 22:36
  3. Custom Model? Custom View? Custom Delegate?
    By Doug Broadwell in forum Newbie
    Replies: 4
    Last Post: 11th February 2010, 20:23
  4. QListView and custom widgets in each cell
    By T4ng10r in forum Qt Programming
    Replies: 1
    Last Post: 28th December 2009, 10:14
  5. Replies: 1
    Last Post: 5th March 2007, 20:50

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.