Results 1 to 20 of 54

Thread: QTableWidget problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QTableWidget problem

    Quote Originally Posted by MarkoSan View Post
    Will the result be as in first post?
    If you implement it correctly, then yes.

    P.S.:QStyledDelegate has no reference to known class, the link reports "object not found...".
    QStyledItemDelegate a Qt 4.4 class, so the reference won't be valid until 4.4.0 comes out.

  2. The following user says thank you to wysota for this useful post:

    MarkoSan (10th April 2008)

  3. #2
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    111
    Thanked 4 Times in 4 Posts

    Default Re: QTableWidget problem

    Ok, I try to set QTableWidget's item delegate using method setItemDelegate:
    Qt Code:
    1. m_pShoppingCartTableWidget->setItemDelegate(m_pShoppingCartItemDelegate); // sets delegate
    To copy to clipboard, switch view to plain text mode 
    In the last line of method, I get following error:
    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
    Why I cannot set my own delegate??
    Last edited by jacek; 10th April 2008 at 14:03. Reason: changed [code] to [quote]
    Qt 5.3 Opensource & Creator 3.1.2

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: QTableWidget problem

    Quote Originally Posted by MarkoSan View Post
    Why I cannot set my own delegate??
    Make sure you use public inheritance in CShoppingCartDelegate.

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

    MarkoSan (10th April 2008)

  6. #4
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    111
    Thanked 4 Times in 4 Posts

    Default Re: QTableWidget problem

    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:
    Qt Code:
    1. typedef struct
    2. {
    3. qint16 iMerchandizeID;
    4. QString strMerchandizeName;
    5. qreal rMerchandizePrice;
    6. qint16 iMerchandizeQuantity;
    7. qreal rSubtotal;
    8. } structOrder;
    To copy to clipboard, switch view to plain text mode 
    And I've setup the view with:
    Qt Code:
    1. m_pShoppingCartTableView->setShowGrid(false);
    2. m_pShoppingCartTableView->setModel(m_pShoppingCartModel);
    3. m_pShoppingCartTableView->setItemDelegate(m_pShoppingCartItemDelegate);
    4. m_pShoppingCartTableView->horizontalHeader()->hide();
    5. m_pShoppingCartTableView->verticalHeader()->hide();
    6. m_pShoppingCartTableView->horizontalHeader()->setMinimumSectionSize(1);
    7. m_pShoppingCartTableView->verticalHeader()->setMinimumSectionSize(1);
    To copy to clipboard, switch view to plain text mode 
    I'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?
    Last edited by MarkoSan; 11th April 2008 at 10:19. Reason: spelling error
    Qt 5.3 Opensource & Creator 3.1.2

  7. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QTableWidget problem

    It means the model is not set up incorrectly.

  8. #6
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    111
    Thanked 4 Times in 4 Posts

    Default Re: QTableWidget problem

    Ok, but how do I make model aware of its QList datasource?
    Qt 5.3 Opensource & Creator 3.1.2

  9. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QTableWidget problem

    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.

  10. The following user says thank you to wysota for this useful post:

    MarkoSan (11th April 2008)

  11. #8
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    111
    Thanked 4 Times in 4 Posts

    Default Re: QTableWidget problem

    Well, my friends, I've done that:
    Qt Code:
    1. #ifndef CSHOPPINGCARTITEM_H_
    2. #define CSHOPPINGCARTITEM_H_
    3.  
    4. #include <QStandardItem>
    5.  
    6. class CShoppingCartItem : public QStandardItem
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. CShoppingCartItem(QObject* parent=0);
    12. };
    13.  
    14. #endif /*CSHOPPINGCARTITEM_H_*/
    To copy to clipboard, switch view to plain text mode 
    and its .cpp companion:
    Qt Code:
    1. #include "CShoppingCartItem.h"
    2.  
    3. CShoppingCartItem::CShoppingCartItem(QObject* parent)
    4. {
    5. }
    To copy to clipboard, switch view to plain text mode 
    and I get these errors:
    Qt Code:
    1. mingw32-make
    2. mingw32-make -f Makefile.Debug
    3. mingw32-make[1]: Entering directory `C:/Documents and Settings/markofr/workspace/Client'
    4. 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
    5. debug\moc_CShoppingCartItem.cpp:37: error: `staticMetaObject' is not a member of `QStandardItem'
    6. debug\moc_CShoppingCartItem.cpp: In member function `virtual void* CShoppingCartItem::qt_metacast(const char*)':
    7. debug\moc_CShoppingCartItem.cpp:51: error: `qt_metacast' is not a member of `QStandardItem'
    8. debug\moc_CShoppingCartItem.cpp: In member function `virtual int CShoppingCartItem::qt_metacall(QMetaObject::Call, int, void**)':
    9. debug\moc_CShoppingCartItem.cpp:56: error: `qt_metacall' is not a member of `QStandardItem'
    10. mingw32-make[1]: *** [debug/moc_CShoppingCartItem.o] Error 1
    11. mingw32-make[1]: Leaving directory `C:/Documents and Settings/markofr/workspace/Client'
    12. mingw32-make: *** [debug] Error 2
    To copy to clipboard, switch view to plain text mode 
    What am I doing wrong?
    Qt 5.3 Opensource & Creator 3.1.2

  12. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QTableWidget problem

    QStandardItem is not a QObject.

  13. The following user says thank you to wysota for this useful post:

    MarkoSan (11th April 2008)

  14. #10
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    111
    Thanked 4 Times in 4 Posts

    Red face Re: QTableWidget problem

    Quote Originally Posted by wysota View Post
    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.
    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

  15. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QTableWidget problem

    QStandardItem docs, section "Subclassing".

  16. The following user says thank you to wysota for this useful post:

    MarkoSan (11th April 2008)

  17. #12
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    111
    Thanked 4 Times in 4 Posts

    Red face Re: QTableWidget problem

    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:
    Qt Code:
    1. #ifndef CSHOPPINGCARTITEM_H_
    2. #define CSHOPPINGCARTITEM_H_
    3.  
    4. // qt includes
    5. #include <QStandardItem>
    6.  
    7. static const int STRUCT_ORDER_TYPE=1001;
    8.  
    9. class CShoppingCartItem : public QStandardItem
    10. {
    11. public:
    12. CShoppingCartItem(QObject* parent=0);
    13.  
    14. int type() const;
    15. };
    16.  
    17. #endif /*CSHOPPINGCARTITEM_H_*/
    To copy to clipboard, switch view to plain text mode 
    Implementation:
    Qt Code:
    1. #include "CShoppingCartItem.h"
    2.  
    3. CShoppingCartItem::CShoppingCartItem(QObject* parent)
    4. {
    5. }
    6.  
    7. int CShoppingCartItem::type() const
    8. {
    9. return STRUCT_ORDER_TYPE;
    10. }
    To copy to clipboard, switch view to plain text mode 
    Where do I put my struct?!
    Qt 5.3 Opensource & Creator 3.1.2

  18. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QTableWidget problem

    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.

  19. #14
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    111
    Thanked 4 Times in 4 Posts

    Default Re: QTableWidget problem

    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

Similar Threads

  1. Replies: 3
    Last Post: 11th August 2007, 10:00
  2. experiencing problem at printing out QTableWidget
    By rmagro in forum Qt Programming
    Replies: 9
    Last Post: 27th June 2007, 16:04
  3. QTableWidget Problem, setRowWidget? :P
    By VireX in forum Newbie
    Replies: 17
    Last Post: 6th April 2007, 18:12
  4. QTableWidget editing question
    By Trasmeister in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2006, 18:46
  5. Problem inserting in QTableWidget
    By DPinLV in forum Qt Programming
    Replies: 2
    Last Post: 2nd August 2006, 00:10

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.