Results 1 to 5 of 5

Thread: A QListWidget in a QTableWidget cell ?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default A QListWidget in a QTableWidget cell ?

    Hello,

    I would like to add a QListWidget in a QTableWidget cell.
    I know how to add checkboxes (simply set the cell item checked or unchecke, like this : Item_0->setCheckState(Qt::Checked); ) but I don't understand how to add other QListWidgets. For adding checkboxes, we simply modify the flags value of the QtableWidgetItem in the cell... But there isn't any flags concerning QlistWidgets.

    Reading the QTableWidgetItem documentation, they say :
    Subclassing
    When subclassing QTableWidgetItem to provide custom items, it is possible to define new types for them so that they can be distinguished from standard items. The constructors for subclasses that require this feature need to call the base class constructor with a new type value equal to or greater than UserType.
    See also QTableWidget, Model/View Programming, QListWidgetItem, and QTreeWidgetItem.
    And here can be found the UserType documentation.

    Is it the slution for adding QListWidgets in my QTableItems ?
    If yes, could you explain me a bit more, please ? I don't understad very well what does it means

    Thanks for your help





    PS : Working code example :
    Qt Code:
    1. void Table_impl::SLOT_add_row()
    2. {
    3. QListWidget *A_listWidget;
    4. A_listWidget = new QListWidget(table);
    5.  
    6. QListWidgetItem *__item = new QListWidgetItem(A_listWidget);
    7. __item->setText("Bla bla bla...");
    8.  
    9. table->setRowCount(table->rowCount() + 1);
    10.  
    11. QTableWidgetItem *Item_1 = new QTableWidgetItem("");
    12.  
    13. table->setItem(table->rowCount()-1, 0, Item_0);
    14. //table->setItem(table->rowCount()-1, 1, Item_1);
    15. table->setCellWidget(table->rowCount()-1, 1, A_listWidget);
    16. table->setItem(table->rowCount()-1, 2, Item_2);
    17. table->setItem(table->rowCount()-1, 3, Item_3);
    18.  
    19. Item_0->setCheckState(Qt::Unchecked);
    20. Item_0->setFlags(Item_0->flags() & (~(Qt::ItemIsEditable)));
    21. Item_1->setFlags(Item_1->flags() & (~(Qt::ItemIsEditable)));
    22. Item_2->setFlags(Item_2->flags() & (~(Qt::ItemIsEditable)));
    23.  
    24. this->resize(table->width() + 4, this->height() + table->rowHeight(table->rowCount()-1));
    25. }
    To copy to clipboard, switch view to plain text mode 


    .
    Last edited by Nyphel; 11th April 2007 at 10:28.

Similar Threads

  1. repaint a cell or row in QTableWidget
    By alphaqt in forum Newbie
    Replies: 6
    Last Post: 26th June 2012, 11:21
  2. Center a widget in a cell on a QTableWidget
    By roleroz in forum Qt Programming
    Replies: 16
    Last Post: 5th March 2009, 14:47
  3. Selection of cell with QWidget in QTableWidget
    By Tamara in forum Qt Programming
    Replies: 7
    Last Post: 17th February 2007, 14:11
  4. QTableWidget or QListWidget
    By bpetty in forum Newbie
    Replies: 3
    Last Post: 6th December 2006, 19:40
  5. Replies: 3
    Last Post: 8th September 2006, 18:54

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.