Results 1 to 4 of 4

Thread: Deselecting selection on QTableWidget

  1. #1
    Join Date
    Aug 2009
    Location
    Brisbane, Australia
    Posts
    75
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Deselecting selection on QTableWidget

    Hi,

    I would like to deselect what I have currently selected on a QTableWidget. My code goes through and removes some rows from the table. If all rows are removed while a row is selected it crashes. If nothing is selected when everything is removed it doesn't crash.

    I have tried the following with no luck:
    Qt Code:
    1. table->setCurrentCell(-1,-1);
    2. table->clearSelection();
    To copy to clipboard, switch view to plain text mode 

    Thanks
    Brendan

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Deselecting selection on QTableWidget

    Please, could you provide a minimal compilable program that reproduce your issue.

  3. #3
    Join Date
    Aug 2009
    Location
    Brisbane, Australia
    Posts
    75
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Deselecting selection on QTableWidget

    It's bit of a mess because I have a pair of vector arrays one for labels on the table another for pointers to endpoints.

    You will need to substitute something for TestEndpoint.

    Qt Code:
    1. std::vector<QLabel*> m_endpoint_labels;
    2. std::vector<TestEndpoint*> m_testendpoint_items;
    3. //QTableWidget *endpoint_table;
    4.  
    5. void Add_Data(string serial_num, TestEndpoint*e)
    6. {
    7. endpoint_table->setRowCount(endpoint_table->rowCount() + 1);
    8.  
    9. QLabel *lbl = new QLabel(serial_num.c_str());
    10. endpoint_table->setCellWidget(endpoint_table->rowCount() - 1, 0, lbl);
    11.  
    12. m_endpoint_labels.push_back(lbl);
    13. m_testendpoint_items.push_back(e->getEndpoint());
    14. }
    15.  
    16. void MyQtApp::onRemoveFailedButton()
    17. {
    18. unsigned int count = 0;
    19. // Look through all endpoints...
    20. while(count < m_testendpoint_items.size()) {
    21. // Is the endpoint offline?
    22. if(!m_testendpoint_items[count]->getEndpoint().isOnline()) {
    23.  
    24. delete m_endpoint_labels[count];
    25. m_testendpoint_items.erase(m_testendpoint_items.begin() + count);
    26. m_endpoint_labels.erase(m_endpoint_labels.begin() + count);
    27.  
    28. endpoint_table->removeRow(count);
    29.  
    30. } else count ++;
    31. }
    32. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Aug 2009
    Location
    Brisbane, Australia
    Posts
    75
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: Deselecting selection on QTableWidget

    I found the problem.

    I had a currentCellChanged() event that was being called.

    Passing me currentRow = -1.

    I was then doing the following, which I think crashed it.

    Qt Code:
    1. QLabel* lbl = (QLabel *) endpoint_table->cellWidget(currentRow, ENDPOINT_DATA_COL);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QTableWidget row selection
    By BingoMaster in forum Newbie
    Replies: 5
    Last Post: 17th October 2009, 22:39
  2. QTableWidget, selection problem
    By stella1016 in forum Qt Programming
    Replies: 2
    Last Post: 6th October 2009, 15:49
  3. Selection in QTableWidget
    By Nippler in forum Qt Programming
    Replies: 3
    Last Post: 30th April 2008, 08:32
  4. QTableWidget and column selection
    By Arthur in forum Qt Programming
    Replies: 1
    Last Post: 30th March 2007, 15:02
  5. Selection of cell with QWidget in QTableWidget
    By Tamara in forum Qt Programming
    Replies: 7
    Last Post: 17th February 2007, 14:11

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.