Results 1 to 5 of 5

Thread: A QListWidget in a QTableWidget cell ?

  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 11:28.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: A QListWidget in a QTableWidget cell ?

    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
    It means, you need to subclass QTableWidgetItem, and give the constructor a user type.
    Qt Code:
    1. ListTableItem: public QTableWidgetItem
    2. {
    3. //Where 'ListItem' is a constant defined somewhere like #define ListItem 100
    4. ListTableItem(int type = QTableWidgetItem::UserType + ListItem):QTableWidgetItem(type){}
    5. ///The rest of the class
    6. };
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: A QListWidget in a QTableWidget cell ?

    Ok, thanks, but I don't understand thoses UserType...

    Trolltech seems to reserve the Types from 0 to 1000.
    Why ? Is there 1000 deffirent base types in Qt ?

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: A QListWidget in a QTableWidget cell ?

    Ok, thanks, but I don't understand thoses UserType...
    Its just a constant value, through which a type is known throughout the framework.

    Why ? Is there 1000 deffirent base types in Qt ?
    Probably not, but since there is no shortage on ints, why not reserve 1000?
    It leaves more then enough for your user types, surely you will not need int range-1000 types of your own.

  5. #5
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: A QListWidget in a QTableWidget cell ?

    Huhu hanks for thoses hints

Similar Threads

  1. repaint a cell or row in QTableWidget
    By alphaqt in forum Newbie
    Replies: 6
    Last Post: 26th June 2012, 12:21
  2. Center a widget in a cell on a QTableWidget
    By roleroz in forum Qt Programming
    Replies: 16
    Last Post: 5th March 2009, 15:47
  3. Selection of cell with QWidget in QTableWidget
    By Tamara in forum Qt Programming
    Replies: 7
    Last Post: 17th February 2007, 15:11
  4. QTableWidget or QListWidget
    By bpetty in forum Newbie
    Replies: 3
    Last Post: 6th December 2006, 20:40
  5. Replies: 3
    Last Post: 8th September 2006, 19: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.