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

    Yes, you are wrong You need a custom delegate that will render the data fetched from a single item using different item roles (like the text, icon, etc. - your custom roles included).
    So, I can use existing model classes, existing view classes and I only reimplement delegate class?

    And to be honest, I'd do it completely differently. I'd have a table with three columns and simply span appropriate rows across all columns.
    The problem is that this table must be wide as little as possible, because on 17" touch monitor I am very limited with its width. About 90% of desktop (from 17") there is a some operation window. But because your ideas helped me a lot, can you provide me some screenshot, what did you mean by quote?
    Qt 5.3 Opensource & Creator 3.1.2

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 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
    So, I can use existing model classes, existing view classes and I only reimplement delegate class?
    Yes, that's correct. QStandardItemModel has everything you might need.

    The problem is that this table must be wide as little as possible, because on 17" touch monitor I am very limited with its width. About 90% of desktop (from 17") there is a some operation window. But because your ideas helped me a lot, can you provide me some screenshot, what did you mean by quote?
    I don't have a screenshot. I meant to use QTableView::setSpan().

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

    MarkoSan (9th April 2008)

  4. #3
    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

    But, which delegate should I use, QItemDelegate or QAbstractItemDelegate? At this moment, I am totaly confused ...
    Qt 5.3 Opensource & Creator 3.1.2

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 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.

  6. #5
    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

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 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.

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

    MarkoSan (10th April 2008)

  9. #7
    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

  10. #8
    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.

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

    MarkoSan (10th April 2008)

  12. #9
    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

  13. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 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.

  14. #11
    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

  15. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 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.

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

    MarkoSan (11th April 2008)

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.