Results 1 to 20 of 43

Thread: QTableWidget issues

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2006
    Posts
    72
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableWidget issues

    Thanx for reply, but I don't get it completely. I am looking at some examples in Qt Assistant and I can't catch when are those methods from QItemDelegate's class child called. Where is in my case, drawDisplay() method called?

  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 issues

    The delegate is used by the view to render items. So every time an item needs to be drawn, the delegate is called to do that. drawDisplay is called by paint() which in turn is called by the view.

  3. #3
    Join Date
    Nov 2006
    Posts
    72
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableWidget issues

    Quote Originally Posted by wysota View Post
    The delegate is used by the view to render items. So every time an item needs to be drawn, the delegate is called to do that. drawDisplay is called by paint() which in turn is called by the view.
    In my case, is that going to happen when I insert row in my table or when I set new QTableWidgetItem for my new cell? Should paint() be called in code, or "automatically"?

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

    The delegate is called automatically whenever the view feels like repainting an item.

  5. #5
    Join Date
    Nov 2006
    Posts
    72
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableWidget issues

    Thanx for replies and sorry for stupid questions . What methods I need to reimplement in order to get my QItemDelegate to paint only 6th colum? Secondly, the painting depends on data (3 integer variables), as you can see on picture. How can I send those integers to QItemDelegate so the delegate can paint cell properly? Is there another way?

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

    Quote Originally Posted by Djony View Post
    What methods I need to reimplement in order to get my QItemDelegate to paint only 6th colum?
    paint() and/or drawDisplay(), depending on which class you subclass. It also depends how you install the delegate. You can install it for a single column only or for all columns (then you have to reimplement paint() to call the base class implementation for columns other then 6th.

    Secondly, the painting depends on data (3 integer variables), as you can see on picture. How can I send those integers to QItemDelegate so the delegate can paint cell properly? Is there another way?
    There are different ways to do this. I'd suggest using different item roles for each "colour" or setting a list of values as the data for the display role (setData(6, Qt::DisplayRole, QList<int>() << 1 << 2 << 3)) and then retrieve each value from within the delegate.

    And I think it would be easier for you to subclass QItemDelegate and reimplement its paint() method than to go for drawDisplay().

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

    Djony (4th December 2006)

  8. #7
    Join Date
    Nov 2006
    Posts
    72
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableWidget issues

    Quote Originally Posted by wysota View Post
    paint() and/or drawDisplay(), depending on which class you subclass. It also depends how you install the delegate. You can install it for a single column only or for all columns (then you have to reimplement paint() to call the base class implementation for columns other then 6th.
    How can I install delegate for just single column? I have decided to use QItemDelegate and to reimplement it's paint metod.

    Quote Originally Posted by wysota View Post
    There are different ways to do this. I'd suggest using different item roles for each "colour" or setting a list of values as the data for the display role (setData(6, Qt:isplayRole, QList<int>() << 1 << 2 << 3)) and then retrieve each value from within the delegate.
    Maybe I've explained it wrong in previous post The data shown in that "colored column" will not be changed by the user. It should be shown and "colored" by the delegate based upon the values that some other class reads from SQLITE 3 database. If you mean't the same thing, which methods from QItemDelegate I need to reimplement and how (in which direction, I don't have any idea)? How can I "send" those integers to delegate so he can color cells?

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

    Quote Originally Posted by Djony View Post
    How can I install delegate for just single column?
    First thing to do is to browse QAbstractItemView docs and find the answer there.


    If you mean't the same thing,
    I did.

    which methods from QItemDelegate I need to reimplement and how (in which direction, I don't have any idea)? How can I "send" those integers to delegate so he can color cells?
    My previous answer still stands. Please read about item roles and Qt MVC implementation.

  10. #9
    Join Date
    Nov 2006
    Posts
    72
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableWidget issues

    Thank you for replies. I've read documentation about item roles, models, views, delegates etc. If I understood you right, you are suggesting me to create model and reimplement it's setData() method and to store list of values in it (I am wondering at the moment which model class should I use, considering the fact that I am using QTableWidget. Should it be QStandardItemModel or I need to subclass QAbstractItemModel class?). After that, my delegate class will with data() get list of values and based on those values color the cell. That's cool.
    But, when reimplementing paint() method I need to know cordinates (and dimensions) of whole cell, so I can paint properly. How can I retrieve cordinates (and dimensions) of whole cell in delegate class? (Maybe I've asked this before, but I don't get it...)
    Again, thanx for replies

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

    If you use QTableWidget, then you don't need to touch the model, as QTableWidget already implements one for you. Just use QTableWidgetItem::setData() to store data and implement a custom delegate to display it.

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

    Djony (14th December 2006)

  13. #11
    Join Date
    Nov 2006
    Posts
    72
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableWidget issues

    OK, but can you please tell me how can I retrieve width of table cell in my delegate class?

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

    QStyleOptionViewItem::rect

Similar Threads

  1. print QTableWidget
    By chak_med in forum Qt Programming
    Replies: 3
    Last Post: 4th November 2006, 18:46
  2. parsing QtableWidget from a QStackedWidget
    By rosmarcha in forum Qt Programming
    Replies: 10
    Last Post: 13th October 2006, 14:36
  3. QTableWidget editing question
    By Trasmeister in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2006, 18:46
  4. Replies: 6
    Last Post: 5th March 2006, 21:05
  5. How to obtain the width of a QTableWidget?
    By Giel Peters in forum Qt Programming
    Replies: 3
    Last Post: 9th January 2006, 22:34

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.