PDA

View Full Version : QListView: Custom or not



Archa4
8th February 2011, 10:05
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...

Archa4
8th February 2011, 12:25
So i think i'll need

class ListModel : public QAbstractListModel
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:

class ListModel : public QAbstractListModel
{
Q_OBJECT
public:
ListModel(const QString array[20][3], QObject *parent = 0)
: QAbstractListModel(parent), str(array[20][3]){}

int rowCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role) const;

private:
QString str;
};

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?

aamer4yu
8th February 2011, 13:39
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 QListWidget and delegates. Have a look at QStyledItemDelegate and QItemDelegate

Also look at star rating example in Qt Demos

Archa4
8th February 2011, 13:45
Where can i look at those Qt Demos?

aamer4yu
8th February 2011, 13:46
If you have installed Qt, it must be in ur QTDIR/bin/qtdemo..

Archa4
8th February 2011, 14:04
Hm... I have NokiaQtSdk, i found that qtdemo, but i cannot launch it...
It throws many errors:

WARNING: c:\NokiaQtSDK\Simulator\Qt\mingw\lib\qtmaind.prl:1 : Unescaped backslashes are deprecated.

WARNING: c:\NokiaQtSDK\Simulator\Qt\mingw\lib\QtDeclarative d.prl:1: Unescaped backslashes are deprecated.

WARNING: c:\NokiaQtSDK\Simulator\Qt\mingw\lib\QtSqld.prl:1: Unescaped backslashes are deprecated.

WARNING: c:\NokiaQtSDK\Simulator\Qt\mingw\lib\QtXmld.prl:1: Unescaped backslashes are deprecated.

WARNING: c:\NokiaQtSDK\Simulator\Qt\mingw\lib\QtGuid.prl:1: Unescaped backslashes are deprecated.

WARNING: c:\NokiaQtSDK\Simulator\Qt\mingw\lib\QtNetworkd.pr l:1: Unescaped backslashes are deprecated.

WARNING: c:\NokiaQtSDK\Simulator\Qt\mingw\lib\QtCored.prl:1 : Unescaped backslashes are deprecated.

WARNING: c:\NokiaQtSDK\Simulator\Qt\mingw\lib\qtmaind.prl:1 : Unescaped backslashes are deprecated.

WARNING: c:\NokiaQtSDK\Simulator\Qt\mingw\lib\qtmain.prl:1: Unescaped backslashes are deprecated.

WARNING: c:\NokiaQtSDK\Simulator\Qt\mingw\lib\QtDeclarative .prl:1: Unescaped backslashes are deprecated.

c:/nokiaqtsdk/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../../mingw32/bin/ld.exe: cannot find -lQtHelpd

collect2: ld returned 1 exit status

mingw32-make[1]: *** [..\..\bin\qtdemo.exe] Error 1

mingw32-make: *** [debug] Error 2

Процесс "C:/NokiaQtSDK/mingw/bin/mingw32-make.exe" завершился с кодом %2.
Возникла ошибка при сборке проекта qtdemo (цель: Ð*мулятор Qt)
Во время выполнения сборки на этапе "Сборка"

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