Results 1 to 4 of 4

Thread: again problem in add items in tablewidget

  1. #1
    Join Date
    Nov 2006
    Location
    gurgaon
    Posts
    49
    Thanks
    12
    Qt products
    Qt4
    Platforms
    MacOS X

    Question again problem in add items in tablewidget

    hi all
    i wanna add items in tablewidget on one buttonclick
    like when i click button then item both items item n item1 shud enter at one click...
    bt if i follow the following way then t first enter the item1,then item
    and next is after opening i didnt get the check button....under column 0
    plz do suggest me..wht to do nw


    void form5::addItem()
    {
    int row=0;
    int RowCount=0;
    row=tableWidget->rowCount();
    tableWidget->setRowCount(row+1);
    QTableWidgetItem *item=new QTableWidgetItem("abc");
    item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled |Qt::ItemIsUserCheckable);
    tableWidget->setItem(RowCount,0,item);

    QTableWidgetItem *item1=new QTableWidgetItem("123");
    tableWidget->insertRow(row);
    tableWidget->setItem(RowCount,1,item1);


    TIA
    thanks & regards
    --------------------
    jyoti

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

    Default Re: again problem in add items in tablewidget

    Invoke QTableWidget::setRowCount() OR QTableWidget::insertRow(), not both. Variable
    "int RowCount" is initialized as zero and never changed.
    Qt Code:
    1. int row=tableWidget->rowCount();
    2. tableWidget->insertRow(row);
    3.  
    4. tableWidget->setItem(row,0,item);
    5.  
    6. QTableWidgetItem *item1=...
    7. tableWidget->setItem(row,1,item1);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

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

    jyoti (24th November 2006)

  4. #3
    Join Date
    Nov 2006
    Location
    gurgaon
    Posts
    49
    Thanks
    12
    Qt products
    Qt4
    Platforms
    MacOS X

    Question Re: again problem in add items in tablewidget

    thanks for rplying...its helpful...
    n can u tell how we can show checkbox which having property QT::ItemIsUserCheckable
    i mean when user checked it then another form should be opened
    thanks & regards
    --------------------
    jyoti

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

    Default Re: again problem in add items in tablewidget

    Qt Code:
    1. // initialize a checkable item
    2. QTableWidgetItem* item = ...
    3. item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
    4. item->setCheckState(Qt::Unchecked);
    To copy to clipboard, switch view to plain text mode 

    To react to check state changes, connect to signal QTableWidget::itemChanged(). This signal is emitted whenever the data of an item has changed. The corresponding item is passed as a parameter. Check it's check state and do corresponding actions. Just be aware that the signal is emitted whenever any data of the items changes, it has not necessarily been a change of the check state.

    QTableWidget nor any QAbstractItemView descendant class offers any signal which would inform only check state changes. To only react to check state changes, Trolltech suggests you to reimplement QTableWidgetItem::setData().

    PS. once again this has nothing to do with Qt Designer which is a tool for designing and building graphical user interfaces.
    J-P Nurmi

Similar Threads

  1. Replies: 2
    Last Post: 23rd November 2006, 11:33
  2. QGraphicsItem problem - how to save items info ??
    By aamer4yu in forum Qt Programming
    Replies: 3
    Last Post: 17th October 2006, 12:17
  3. Selection problem in QTreeView
    By Valheru in forum Qt Programming
    Replies: 3
    Last Post: 7th October 2006, 16:02
  4. Selective highlighting of Items
    By Kapil in forum Qt Programming
    Replies: 3
    Last Post: 26th May 2006, 12:20
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.