Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 54

Thread: QTableWidget problem

  1. #21
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTableWidget problem

    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.

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

    Default Re: QTableWidget problem

    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

  3. #23
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    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.

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

    MarkoSan (10th April 2008)

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

    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

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

    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.

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

    MarkoSan (10th April 2008)

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

    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

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

    Default Re: QTableWidget problem

    It means the model is not set up incorrectly.

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

    Default Re: QTableWidget problem

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

  11. #29
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    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.

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

    MarkoSan (11th April 2008)

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

    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

  14. #31
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTableWidget problem

    QStandardItem is not a QObject.

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

    MarkoSan (11th April 2008)

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

    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

  17. #33
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTableWidget problem

    QStandardItem docs, section "Subclassing".

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

    MarkoSan (11th April 2008)

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

    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

  20. #35
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    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.

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

    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

  22. #37
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTableWidget problem

    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].

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

    Default Re: QTableWidget problem

    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?
    Attached Images Attached Images
    Qt 5.3 Opensource & Creator 3.1.2

  24. #39
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTableWidget problem

    You can adjust horizontal stretches and/or size policies of widgets.

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

    Default Re: QTableWidget problem

    Well, I used resize function, but there are no results ...
    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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.