The former inherits the latter, thus the choice is yours. I'd go for QItemDelegate or even QStyledItemDelegate if you use a recent version of Qt.
The former inherits the latter, thus the choice is yours. I'd go for QItemDelegate or even QStyledItemDelegate if you use a recent version of Qt.
Will the result be as in first post?
P.S.:QStyledDelegate has no reference to known class, the link reports "object not found...".
Last edited by MarkoSan; 10th April 2008 at 07:37. Reason: updated contents
Qt 5.3 Opensource & Creator 3.1.2
If you implement it correctly, then yes.
QStyledItemDelegate a Qt 4.4 class, so the reference won't be valid until 4.4.0 comes out.P.S.:QStyledDelegate has no reference to known class, the link reports "object not found...".
MarkoSan (10th April 2008)
Ok, I try to set QTableWidget's item delegate using method setItemDelegate:In the last line of method, I get following error:Qt Code:
m_pShoppingCartTableWidget->setItemDelegate(m_pShoppingCartItemDelegate); // sets delegateTo copy to clipboard, switch view to plain text modeWhy I cannot set my own delegate??mingw32-make
mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `C:/Documents and Settings/markofr/workspace/Client'
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_SQL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\..\..\Qt\4.3.4\include\QtCore" -I"..\..\..\..\Qt\4.3.4\include\QtCore" -I"..\..\..\..\Qt\4.3.4\include\QtGui" -I"..\..\..\..\Qt\4.3.4\include\QtGui" -I"..\..\..\..\Qt\4.3.4\include\QtSql" -I"..\..\..\..\Qt\4.3.4\include\QtSql" -I"..\..\..\..\Qt\4.3.4\include" -I"c:\Qt\4.3.4\include\ActiveQt" -I"debug" -I"." -I"..\..\..\..\Qt\4.3.4\mkspecs\win32-g++" -o debug\COperationWIndow.o COperationWIndow.cpp
COperationWIndow.cpp: In member function `void COperationWIndow::createShoppingCartTableWidget()' :
COperationWIndow.cpp:336: error: `QAbstractItemDelegate' is an inaccessible base of `CShoppingCartDelegate'
mingw32-make[1]: *** [debug/COperationWIndow.o] Error 1
mingw32-make[1]: Leaving directory `C:/Documents and Settings/markofr/workspace/Client'
mingw32-make: *** [debug] Error 2
Last edited by jacek; 10th April 2008 at 14:03. Reason: changed [code] to [quote]
Qt 5.3 Opensource & Creator 3.1.2
MarkoSan (10th April 2008)
So, wysota, I've finnaly setup the table view. It is blank rectangle with white background. Now, like your hint was telling me, I used QModelIndex (not subclassed). How do I notify now the model about data source, which is QList of:And I've setup the view with:Qt Code:
typedef struct { qint16 iMerchandizeID; QString strMerchandizeName; qreal rMerchandizePrice; qint16 iMerchandizeQuantity; qreal rSubtotal; } structOrder;To copy to clipboard, switch view to plain text modeI've copied this chunk of code from pixelator example and I've reused it. If i comment the first line, I still do not get grid (for instance). Does this mean view is not setup properly?Qt Code:
m_pShoppingCartTableView->setShowGrid(false); m_pShoppingCartTableView->setModel(m_pShoppingCartModel); m_pShoppingCartTableView->setItemDelegate(m_pShoppingCartItemDelegate); m_pShoppingCartTableView->horizontalHeader()->hide(); m_pShoppingCartTableView->verticalHeader()->hide(); m_pShoppingCartTableView->horizontalHeader()->setMinimumSectionSize(1); m_pShoppingCartTableView->verticalHeader()->setMinimumSectionSize(1);To copy to clipboard, switch view to plain text mode
Last edited by MarkoSan; 11th April 2008 at 10:19. Reason: spelling error
Qt 5.3 Opensource & Creator 3.1.2
It means the model is not set up incorrectly.
Ok, but how do I make model aware of its QList datasource?
Qt 5.3 Opensource & Creator 3.1.2
If you don't feel confident in creating your own model, use QStandardItemModel and reimplement QStandardItem by adding your structure to it. I think the docs explain how to do this.
MarkoSan (11th April 2008)
Well, my friends, I've done that:and its .cpp companion:Qt Code:
#ifndef CSHOPPINGCARTITEM_H_ #define CSHOPPINGCARTITEM_H_ #include <QStandardItem> { Q_OBJECT public: }; #endif /*CSHOPPINGCARTITEM_H_*/To copy to clipboard, switch view to plain text modeand I get these errors:Qt Code:
#include "CShoppingCartItem.h" { }To copy to clipboard, switch view to plain text modeWhat am I doing wrong?Qt Code:
mingw32-make mingw32-make -f Makefile.Debug mingw32-make[1]: Entering directory `C:/Documents and Settings/markofr/workspace/Client' g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_SQL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\..\..\Qt\4.3.4\include\QtCore" -I"..\..\..\..\Qt\4.3.4\include\QtCore" -I"..\..\..\..\Qt\4.3.4\include\QtGui" -I"..\..\..\..\Qt\4.3.4\include\QtGui" -I"..\..\..\..\Qt\4.3.4\include\QtSql" -I"..\..\..\..\Qt\4.3.4\include\QtSql" -I"..\..\..\..\Qt\4.3.4\include" -I"c:\Qt\4.3.4\include\ActiveQt" -I"debug" -I"." -I"..\..\..\..\Qt\4.3.4\mkspecs\win32-g++" -o debug\moc_CShoppingCartItem.o debug\moc_CShoppingCartItem.cpp debug\moc_CShoppingCartItem.cpp: In member function `virtual void* CShoppingCartItem::qt_metacast(const char*)': debug\moc_CShoppingCartItem.cpp:51: error: `qt_metacast' is not a member of `QStandardItem' debug\moc_CShoppingCartItem.cpp: In member function `virtual int CShoppingCartItem::qt_metacall(QMetaObject::Call, int, void**)': mingw32-make[1]: *** [debug/moc_CShoppingCartItem.o] Error 1 mingw32-make[1]: Leaving directory `C:/Documents and Settings/markofr/workspace/Client' mingw32-make: *** [debug] Error 2To copy to clipboard, switch view to plain text mode
Qt 5.3 Opensource & Creator 3.1.2
QStandardItem is not a QObject.
MarkoSan (11th April 2008)
I've been searching docs and two books regarind adding custom structore to QStandardItem, however, I did not find it. I do not know how to continue, please help ... Does anyone has example?
Qt 5.3 Opensource & Creator 3.1.2
QStandardItem docs, section "Subclassing".
MarkoSan (11th April 2008)
I've read it, wysota, but I still do not know how to integrate my struct into subclassed QStandardItem. Here is what I've done so far (it is very little), I really would need some deeper help. The header:Implementation:Qt Code:
#ifndef CSHOPPINGCARTITEM_H_ #define CSHOPPINGCARTITEM_H_ // qt includes #include <QStandardItem> static const int STRUCT_ORDER_TYPE=1001; { public: int type() const; }; #endif /*CSHOPPINGCARTITEM_H_*/To copy to clipboard, switch view to plain text modeWhere do I put my struct?!Qt Code:
#include "CShoppingCartItem.h" { } int CShoppingCartItem::type() const { return STRUCT_ORDER_TYPE; }To copy to clipboard, switch view to plain text mode
Qt 5.3 Opensource & Creator 3.1.2
Either as a member variable or as a superclass. Either way you'll have to reimplement other methods mentioned in the docs if you want to use the structure for anything. But before you do, think if you do need the structure at all. You might use QStandardItem without subclassing - just use custom roles and set your data.
How do I use custom roles? I've been reading docs but I still do not see the way how to do this task.
Qt 5.3 Opensource & Creator 3.1.2
Role is simply a number. Just use setData() and data() with a number of your choice but not less than Qt::UserRole. I think the docs are quite clear about it. You can also take a look at the wiki article about [wiki=QAbstractItemModel]models[/wiki].
Well, I've reimplemented QAbstractTableModel and QTableView, it works ok. The last step is to reimplement QStandardItem for delegate get to work. But right now I am confused regarding layouts. In the attachemnt there is a GUI of my application module. Well, widgets named "QPUSHBUTTON1" and "QTABLEVIEW" are connected via QVBoxLayout. This vertical layout resided with main operation's window (wich is also vertical layouted with 3 pushbuttons placed under it - the 3 pushbuttons are horiz. layouted) vertical layout in horizontal layout. Now, the layout of QPUSHBUTTON1 and QTABLEVIEW is too wide. Now, how can I make main operation window wider and QPUSHBUTTON1 with QTABLEVIEW narrower. Do I have to begin experiment with layouts or the widgets inside "actor" layouts?
Qt 5.3 Opensource & Creator 3.1.2
You can adjust horizontal stretches and/or size policies of widgets.
Well, I used resize function, but there are no results ...
Qt 5.3 Opensource & Creator 3.1.2
Bookmarks