Results 1 to 3 of 3

Thread: Again QTableWidget and QComboBox delegate

  1. #1
    Join Date
    Feb 2007
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Again QTableWidget and QComboBox delegate

    I've gone through the older threads about this subject but didn't find anything regarding my problem at hand:

    So I'm creating a QTableWidget which has some of its columns using a custom delegate which returns a QComboBox editor. My problem is that I cannot get it to work in all situations.

    For example, I have my own ExcelDlg Dialog and in its constructor I create a QTableWidget and set it to using my delegate.

    Like this:
    Qt Code:
    1. QStringList values;
    2. values
    3. << "DESC"
    4. << "POS"
    5. << "ABNORMAL INTERRUPTION"
    6. << "TESTI VAAN"
    7. << "VIELÄ YKS";
    8.  
    9. cDropdownTableWidgetItemDelegate delegate;
    10. delegate.setValues(values);
    11.  
    12. QTableWidget *table = new QTableWidget(2,3,this);
    13. table->setItemDelegate(&delegate);
    14.  
    15. lo = new QHBoxLayout();
    16. lo->addWidget(table);
    To copy to clipboard, switch view to plain text mode 
    Unfortunately the result is an empty table, no cells of any kind, only horizontal and vertical header items are displayed correctly.

    But when I use it in a newly created dialog, for example:
    Qt Code:
    1. QStringList values;
    2. values
    3. << "DESC"
    4. << "POS"
    5. << "ABNORMAL INTERRUPTION"
    6. << "TESTI VAAN"
    7. << "VIELÄ YKS";
    8.  
    9. cDropdownTableWidgetItemDelegate delegate;
    10. delegate.setValues(values);
    11.  
    12. QDialog *dlg = new QDialog();
    13.  
    14. QTableWidget *table = new QTableWidget(2,3,dlg);
    15. table->setItemDelegate(&delegate);
    16.  
    17. dlg->exec();
    To copy to clipboard, switch view to plain text mode 

    It works fine. What is happening? Why is it not working in the upper example?

    If needed, i can post the code to my delegate.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Again QTableWidget and QComboBox delegate

    In the first case the item delegate goes out of scope (you might want to allocate it on the heap instead). In the second case QDialog::exec() blocks so the stack object remains valid until the dialog is accepted or rejected.
    J-P Nurmi

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

    Aki-Matti (5th March 2008)

  4. #3
    Join Date
    Feb 2007
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Again QTableWidget and QComboBox delegate

    It works! I should've seen that happening myself, though...

    Thank you for your help!

Similar Threads

  1. QComboBox in QTableWidget : display troubles.
    By Nyphel in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2007, 23:29
  2. updating database with custom delegate
    By Shaitan in forum Qt Programming
    Replies: 4
    Last Post: 17th July 2007, 10:34
  3. QTableWidget editing question
    By Trasmeister in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2006, 18:46
  4. QComboBox inside QTableWidget
    By campana in forum Qt Programming
    Replies: 7
    Last Post: 20th March 2006, 17:22

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.