Results 1 to 14 of 14

Thread: How to suppress cellClicked() signal from QTableWidget item

  1. #1
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Qt products
    Qt4 Qt5
    Platforms
    Windows
    Thanks
    92
    Thanked 16 Times in 16 Posts

    Default How to suppress cellClicked() signal from QTableWidget item

    For some particular QTableWidgetItem items, I need to suppress the cellClicked(int, int) signal or I need to disable that item. Is there any way that I can easily do it.
    Thank you.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Wiki edits
    15

    Default Re: How to suppress cellClicked() signal from QTableWidget item

    Do you want to disable the clickable option of the item, then set the appropriate flag for the item.

    If you want to just supress the cellClicked() then it is not possible, you will have to handle that in the connected slot, by identifying the item by row and col.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Qt products
    Qt4 Qt5
    Platforms
    Windows
    Thanks
    92
    Thanked 16 Times in 16 Posts

    Default Re: How to suppress cellClicked() signal from QTableWidget item

    Yeah, disable clickable option will do.

    I tried,
    Qt Code:
    1. setCurrentCell(nRow, nCol, QItemSelectionModel::NoUpdate)
    To copy to clipboard, switch view to plain text mode 
    But in my slot, I'm still find the cellClicked() signal for that cell getting emitted.
    BTW, I'm having a Icon for those cells which I'm going to click, I'm setting the icon using setItem(nRow, nCol, new QTableWidgetItem(QIcon(":/imgs/updateIcon.png"), ""); Will that cause any problem?

    I need to disable clickable option some particular cells. Thank you.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: How to suppress cellClicked() signal from QTableWidget item

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Wiki edits
    15

    Default Re: How to suppress cellClicked() signal from QTableWidget item

    BTW, I'm having a Icon for those cells which I'm going to click, I'm setting the icon using setItem(nRow, nCol, new QTableWidgetItem(QIcon(":/imgs/updateIcon.png"), ""); Will that cause any problem?
    First be clear of what you want.
    1. Do you want the item/icon to be clickable and not emit the signal
    You cannot stop/supress the signal, you can only filter it out in the slot.

    2.Do you want the item not to be clickable
    If yes, then use item's API to disable click
    Qt Code:
    1. QTableWidgetItem::setFlags(flags() & ~Qt::ItemIsSelectable)
    To copy to clipboard, switch view to plain text mode 


    My aim is to disable some particular cells. Thank you.
    Hmm, now you want to disable
    Qt Code:
    1. QTableWidgetItem::setFlags(flags() & ~Qt::ItemIsEnabled)
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  6. #6
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Qt products
    Qt4 Qt5
    Platforms
    Windows
    Thanks
    92
    Thanked 16 Times in 16 Posts

    Default Re: How to suppress cellClicked() signal from QTableWidget item

    Thank you Wysota & Santosh,

    If I click on a particular cell, I don't want cellClicked() signal from that cell. I'm trying to give more info what I've done here by saying that cell has got an icon also.

    If disable doesn't emit, cellClicked signal, then it's good for me. I tried to set above said flags, I was still able to see my debug messages in my slot for cellClicked signal.

  7. #7
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Wiki edits
    15

    Default Re: How to suppress cellClicked() signal from QTableWidget item

    If you are still not able to disable the item, please show us what you did.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: How to suppress cellClicked() signal from QTableWidget item

    Forget cellClicked(), focus on the goal you wish to achieve.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Qt products
    Qt4 Qt5
    Platforms
    Windows
    Thanks
    92
    Thanked 16 Times in 16 Posts

    Default Re: How to suppress cellClicked() signal from QTableWidget item

    CResultsTbl is a table.

    Qt Code:
    1. // cresultstbl.cpp ( Class name: CResultsTbl)
    2. void CResultsTbl::loadData()
    3. {
    4. if(s == "true")
    5. {
    6. setItem(nRow, Remediate_Col,
    7. new QTableWidgetItem(QIcon(":/imgs/fixIcon.png"), ""));
    8. }
    9. else if(s == "false")
    10. {
    11. setItem(nRow, Remediate_Col,
    12. new QTableWidgetItem(QIcon(":/imgs/tick.png"), ""));
    13. item(nRow, Remediate_Col)->setFlags(item(nRow, Remediate_Col)->flags() & ~Qt::ItemIsEnabled);
    14. }
    15. else
    16. {
    17. setItem(nRow, Remediate_Col, new QTableWidgetItem());
    18. item(nRow, Remediate_Col)->setFlags(item(nRow, Remediate_Col)->flags() & ~Qt::ItemIsEnabled);
    19. }
    20. }
    To copy to clipboard, switch view to plain text mode 
    For the else if(s == "false") and else, I don't want to add the data into map (inCReportsPage class)
    In CReportsPage, I'm creating objects, of CResultsTbl and processing
    Qt Code:
    1. // vulnTable, patchTable are objects of CResultsTbl
    2. void CReportsPage::onCellClicked(int nRow, int nCol)
    3. {
    4. if(nCol == CResultsTable::Remediate_Col)
    5. {
    6. switch (tabWidget->currentIndex())
    7. {
    8. case 0:
    9. // The below debug message getting printed even for the false case in the above code (cresultstbl.cpp)
    10. qDebug() << vulnTable->item(nRow, CResultsTable::Id_Col)->text();
    11. remIndiv_Map[vulnTable->item(nRow, CResultsTable::Id_Col)->text()] =
    12. vulnTable->item(nRow, CResultsTable::Reference_Col)->text();
    13. break;
    14. case 1:
    15. qDebug() << "Patch Table";
    16. remIndiv_Map[patchTable->item(nRow, CResultsTable::Id_Col)->text()] =
    17. patchTable->item(nRow, CResultsTable::Reference_Col)->text();
    18. break;
    19. case 2:
    20. qDebug() << "Compliance Table";
    21. remIndiv_Map[complTable->item(nRow, CResultsTable::Id_Col)->text()] =
    22. complTable->item(nRow, CResultsTable::Reference_Col)->text();
    23. break;
    24. default:
    25. break;
    26. }
    27.  
    28. if(!indivRem_BatchTimer->isActive())
    29. {
    30. indivRem_BatchTimer->start(5000);
    31. }
    32.  
    33. }
    34. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by rawfool; 21st June 2013 at 07:16.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: How to suppress cellClicked() signal from QTableWidget item

    You don't want to add the data into what map?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Qt products
    Qt4 Qt5
    Platforms
    Windows
    Thanks
    92
    Thanked 16 Times in 16 Posts

    Default Re: How to suppress cellClicked() signal from QTableWidget item

    Kindly check my comment in the code. Thank you for helping.
    Qt Code:
    1. switch (tabWidget->currentIndex())
    2. {
    3. case 0:
    4. // The below debug message getting printed even for the false case in the above code (cresultstbl.cpp)
    5. qDebug() << vulnTable->item(nRow, CResultsTable::Id_Col)->text();
    6.  
    7.  
    8.  
    9. // vv
    10. // Here I'm copying the clicked cell's row data into a QMap (remIndiv_Map)
    11. remIndiv_Map[vulnTable->item(nRow, CResultsTable::Id_Col)->text()] = vulnTable->item(nRow, CResultsTable::Reference_Col)->text();
    12. // ^^
    13. break;
    14. .....
    15. ....
    16. }
    To copy to clipboard, switch view to plain text mode 

    And I don't have the data of which ones are not to be copied, in CReportsPage
    Qt Code:
    1. void CResultsTbl::loadData()
    2. {
    3. if(s == "true")
    4. {
    5. ....
    6. }
    7. // here itself I need to filter data which I'm going to add to QMap (CReportsPage::remIndiv_Map) on click of the cell
    8. else if(s == "false")
    9. {
    10. setItem(nRow, Remediate_Col,
    11. new QTableWidgetItem(QIcon(":/imgs/tick.png"), ""));
    12. item(nRow, Remediate_Col)->setFlags(item(nRow, Remediate_Col)->flags() & ~Qt::ItemIsEnabled);
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by rawfool; 21st June 2013 at 08:56.

  12. #12
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Wiki edits
    15

    Default Re: How to suppress cellClicked() signal from QTableWidget item

    Why are you switch(ing) switch (tabWidget->currentIndex()), you shoud switch for row.

    tabWidget->currentIndex() will return QModelIndex not row number. Row number is a parameter of the slot.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  13. #13
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Qt products
    Qt4 Qt5
    Platforms
    Windows
    Thanks
    92
    Thanked 16 Times in 16 Posts

    Default Re: How to suppress cellClicked() signal from QTableWidget item

    I'm using switch to find the active table in my QTabWidget on which user is clicked the cell. I have 3 tables in my QTabWidget.
    And in a table, I have column called "Fix Issue", where all the cells will have either "Yes" or "Done". So If user clicks on a cell which has "Yes" or "Done", the values are put into QMap for further processing.

    So, here I don't need values of the row of cell which has got "Done", even if users clicks tht cell, I should not add that cell's row data into QMap

  14. #14
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Wiki edits
    15

    Default Re: How to suppress cellClicked() signal from QTableWidget item

    Then show us where and how are you are disabling the item?

    I don't think loadData() is called when user clicks on "Yes" item.

    You will have to disable the item in cellClicked() connected slot.

    [EDIT] Looks like cellClicked() is emitted even if item is disabled.

    You can check if the item is enabled before adding it the map.
    Last edited by Santosh Reddy; 21st June 2013 at 12:09. Reason: updated contents
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  15. The following user says thank you to Santosh Reddy for this useful post:

    rawfool (21st June 2013)

Similar Threads

  1. QTableWidget cellClicked and cellDoubleClicked
    By WikiWiki in forum Qt Programming
    Replies: 1
    Last Post: 10th May 2013, 10:39
  2. Item In QTableWidget
    By Vidhya in forum Qt Programming
    Replies: 3
    Last Post: 26th July 2012, 10:09
  3. QTableWidget signal when item dropped
    By Jeffb in forum Qt Programming
    Replies: 5
    Last Post: 17th February 2012, 09:36
  4. Replies: 2
    Last Post: 1st August 2010, 09:55
  5. Subclassing QLineEdit and suppress signal textChanged
    By Lykurg in forum Qt Programming
    Replies: 2
    Last Post: 15th February 2008, 17:40

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.