Results 1 to 3 of 3

Thread: set ItemDelegate for QTableWidget(s) in QTabWidget(s)

  1. #1
    Join Date
    Jul 2010
    Posts
    41
    Thanks
    6
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default set ItemDelegate for QTableWidget(s) in QTabWidget(s)

    Myapp has a QTabWidget, and every Tab has a QTableWidget.
    I try to set MyItemDelegate on every table.

    When I use following code:
    Qt Code:
    1. for (int i = 0; i < mainTabWidget->count(); ++i)
    2. {
    3. CurrentTabWidget *tmp = getCurrentTabWidget(i);
    4. QAbstractItemDelegate *tmpDelegate = tmp->table->itemDelegate();
    5. if (tmpDelegate)
    6. {
    7. delete tmpDelegate;
    8. tmpDelegate = 0;
    9. }
    10. tmp->table->setItemDelegate(new MyItemDelegate(CurrentTabWidget->table));
    11. }
    To copy to clipboard, switch view to plain text mode 
    MyItemDelegate is set on every Tab, but for exampe:
    if I open three tab and select second one and then close first then second one, I see current Tab (third one) has no itemDelegate (its items aren't painted)
    what's wrong with this code?

    The following code works perfectly:
    Qt Code:
    1. int currentIndex = mainTabWidget->currentIndex();
    2. for (int i = 0; i < mainTabWidget->count(); ++i)
    3. {
    4. mainTabWidget->setCurrentIndex(i);
    5. //currentTab is a pointer to CurrentTabWidget within QTabWidget current Tab
    6. QAbstractItemDelegate *tmpDelegate = currentTab->table->itemDelegate();
    7. if (tmpDelegate)
    8. {
    9. delete tmpDelegate;
    10. tmpDelegate = 0;
    11. }
    12. currentTab->table->setItemDelegate(new MyItemDelegate(currentTab->table));
    13. }
    14. mainTabWidget->setCurrentIndex(currentIndex);
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: set ItemDelegate for QTableWidget(s) in QTabWidget(s)

    At line 10 of first code block, what is "CurrentTabWidget->table"?

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

    srazi (14th November 2010)

  4. #3
    Join Date
    Jul 2010
    Posts
    41
    Thanks
    6
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: set ItemDelegate for QTableWidget(s) in QTabWidget(s)

    Quote Originally Posted by ChrisW67 View Post
    At line 10 of first code block, what is "CurrentTabWidget->table"?
    wow! thanks.
    I think, I need a new glasses

Similar Threads

  1. QtextDocument-ItemDelegate and Painting
    By LynneV in forum Qt Programming
    Replies: 2
    Last Post: 15th November 2010, 16:10
  2. Display ItemDelegate Editor always
    By gast23 in forum Qt Programming
    Replies: 6
    Last Post: 6th September 2010, 04:33
  3. QTreeView and itemDelegate code
    By alexandernst in forum Newbie
    Replies: 1
    Last Post: 22nd April 2010, 17:00
  4. Can I use a QWidget as a renderer in an ItemDelegate?
    By boblebel in forum Qt Programming
    Replies: 2
    Last Post: 2nd May 2009, 20:03
  5. Color table row with ItemDelegate
    By dexjam in forum Newbie
    Replies: 8
    Last Post: 29th June 2006, 12:56

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.