PDA

View Full Version : Example HowTo create custom view



dexjam
11th July 2006, 22:47
Hello,

i have the Problem that i want to have a custom view. Thing is, i want to display detail information of data that is held in a table. My assumption is to derive from QAbstractItemView ... but i do not know exactly how ....

Let's say we do have 6 entities. the table shows 2 of them. Now when i click the "row number" (some QHeaderView thing) i want to open a window that displays all 6 entities using QLabel componets.

So i did the layout using designer, and am trying to subclass QAbstractItemView. But i do receive lot of "No such slots" errors. Has anyone an idea/pointer/code example on how such things are done?

jacek
11th July 2006, 22:52
But i do receive lot of "No such slots" errors.
Could you post the exact error messages? Maybe you forgot to add Q_OBJECT macro?


Has anyone an idea/pointer/code example on how such things are done?
I guess you want to implement something like this: http://doc.trolltech.com/4.2/qdatawidgetmapper.html (note that this class is from Qt 4.2).

dexjam
11th July 2006, 23:26
The exact error message is


Object::connect: No such slot CertInfoView::rowsInserted(QModelIndex,int,int)
Object::connect: No such slot CertInfoView::rowsAboutToBeRemoved(QModelIndex,int ,int)
Object::connect: No such slot CertInfoView::_q_rowsRemoved(QModelIndex,int,int)
Object::connect: No such slot CertInfoView::_q_columnsAboutToBeRemoved(QModelInd ex,int,int)
Object::connect: No such slot CertInfoView::_q_columnsRemoved(QModelIndex,int,in t)
Object::connect: No such slot CertInfoView::reset()
Object::connect: No such slot CertInfoView::doItemsLayout()
Object::connect: No such slot CertInfoView::selectionChanged(QItemSelection,QIte mSelection)
Object::connect: No such slot CertInfoView::currentChanged(QModelIndex,QModelInd ex)

which is actually true because i did not implement these slots. Do i have to do this really?

And yes, QDataWidgetMapper, seems to be exactly what i am looking for ...

Great news, except that i would have to switch to Qt 4.2. Anyway, do you know how to do it using qt 4.1.3 ? Maybe the general idea is info enough ...

jacek
11th July 2006, 23:59
which is actually true because i did not implement these slots. Do i have to do this really?
These errors are a bit weird. These are not abstract slots --- they should be implemented in base classes. Maybe there's something wrong with your class definition? Do you use public inheritance?


Great news, except that i would have to switch to Qt 4.2. Anyway, do you know how to do it using qt 4.1.3 ? Maybe the general idea is info enough ...
Most likely this class doesn't use any mechanisms that aren't present in Qt 4.1. The only problem might be the licence under Qt 4.2 TP1 was released.

dexjam
12th July 2006, 00:16
These errors are a bit weird. These are not abstract slots --- they should be implemented in base classes. Maybe there's something wrong with your class definition? Do you use public inheritance?
Yes i do use public inheritance with QAbstractItemView and QDialog. The Ui::Class is inherited private ...

Am i doing sth. wrong?



Most likely this class doesn't use any mechanisms that aren't present in Qt 4.1. The only problem might be the licence under Qt 4.2 TP1 was released.
So you mean i could simply copy this class into my sources ... if the license is ok of course ...

jacek
12th July 2006, 00:32
Yes i do use public inheritance with QAbstractItemView and QDialog.
The problem is that both QAbstractItemView and QDialog are widgets and all widgets inherit from QObject, so in this case your CertInfoView represents two different QObjects --- Qt doesn't use virtual inheritance from QObject.

As a workaround you could create another class that represents a dialog with CertInfoView on it (this way the view won't have to inherit from QDialog).


So you mean i could simply copy this class into my sources ... if the license is ok of course ...
Well... not simply, because it uses some private Qt headers. You will have to merge QDataWidgetMapper with QDataWidgetMapperPrivate.

Or just use the Heavy Inspiration(tm) technique, if the licence permits it. ;)

dexjam
12th July 2006, 11:06
The problem is that both QAbstractItemView and QDialog are widgets and all widgets inherit from QObject, so in this case your CertInfoView represents two different QObjects --- Qt doesn't use virtual inheritance from QObject.

As a workaround you could create another class that represents a dialog with CertInfoView on it (this way the view won't have to inherit from QDialog).


Ok, thanks for the hint ....