Results 1 to 5 of 5

Thread: Problem with QTableWidget and Signals

  1. #1
    Join Date
    Jun 2007
    Location
    italy
    Posts
    126
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Problem with QTableWidget and Signals

    Hi all,

    I have a QtableWidget defines as follows:

    Qt Code:
    1. tableWidget = new QTableWidget(3, 4, this);
    2.  
    3. for (int row_j=0; row_j < 3; ++row_j)
    4. {
    5. for (int column_i=0; column_i < 4; column_i++)
    6. {
    7. item->setTextAlignment (Qt::AlignCenter);
    8. tableWidget->setItem(row_j, column_i, item);
    9. }
    10. }
    11.  
    12. tableWidget->item(0, 0)->setCheckState ( Qt::Checked ); <------
    13. tableWidget->item(1, 0)->setCheckState ( Qt::Checked ); <------
    14. tableWidget->item(2, 0)->setCheckState ( Qt::Checked ); <------
    15.  
    16. QGroupBox *frameQTable = new QGroupBox(tr(""));
    17.  
    18. QVBoxLayout *TableLayout = new QVBoxLayout(frameQTable);
    19. TableLayout->addWidget (tableWidget);
    20.  
    21. QVBoxLayout *layout = new QVBoxLayout;
    22. layout->addWidget(frameQTable);
    23. setLayout(layout);
    To copy to clipboard, switch view to plain text mode 

    Using the code as the shows by the arrows above, I put into the first cell of each row a CheckBox..

    The Question is :
    is there a way to emit a signal when the I click on the CheckBox?

    So far the only signal is working for me is itemSelectionChanged ():

    Qt Code:
    1. connect(tableWidget, SIGNAL(itemSelectionChanged () ),
    2. this, SIGNAL(completeChanged()));
    To copy to clipboard, switch view to plain text mode 

    that works indeed when I move to another item....
    but not when I put the check..

    Thank you for your kind reply..
    Roberto

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problem with QTableWidget and Signals

    Try connecting to QTableWidget::cellChanged() and check the Qt::CheckStateRole of the item.

    HTH

  3. #3
    Join Date
    Jun 2007
    Location
    italy
    Posts
    126
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with QTableWidget and Signals

    Nothing happens whe I click on the checkbox...
    Ho do I have to use the Qt::CheckStateRole

    Here is the code I use:

    Qt Code:
    1. what I am trying:
    2.  
    3. connect(tableWidget, SIGNAL(cellChanged(0,0) ),
    4. this, SIGNAL(completeChanged()));
    5.  
    6. and then in the method called I have the code:
    7.  
    8. if ( (tableWidget->item(1, 0)->checkState () != Qt::Checked) )
    9. {
    10. return false;
    11. }
    12. else
    13. return true;
    14.  
    15. but nothing..
    To copy to clipboard, switch view to plain text mode 

    Thx

  4. #4
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problem with QTableWidget and Signals

    You must not use values for the arguments of the slot in the connect call!
    (You should get an error message printed for your code, by the way.)

    Try like this
    Qt Code:
    1. connect(tableWidget, SIGNAL(cellChanged(int,int) ),
    2. this, SIGNAL(completeChanged(int,int)));
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void completeChanged(int row, int col)
    2. {
    3. QTableWidgetItem *item = tableWidget->item(row,col);
    4. if (item->checkState() == ...)
    5. ...
    6. }
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to caduel for this useful post:

    rmagro (17th September 2008)

  6. #5
    Join Date
    Jun 2007
    Location
    italy
    Posts
    126
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with QTableWidget and Signals

    BINGOOO!!!

    It works Perfectly...as you suggested..

    GREAT!

    Many thanks..

    Roberto

Similar Threads

  1. QTableWidget signals
    By QiT in forum Newbie
    Replies: 4
    Last Post: 1st April 2007, 14:03

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.