Results 1 to 9 of 9

Thread: Selecting somes cells from a QTableWidget

  1. #1
    Join Date
    Jan 2012
    Posts
    83
    Qt products
    Qt4
    Platforms
    Windows

    Default Selecting somes cells from a QTableWidget

    Hi!
    Can anyone helps in selecting just some cells from a column of a QtableWidget? Is there a specific method for that?
    To be clear, I want to remove some cells from my selection of a given column's data.
    I have tried the following code, but it is not wroking. I have the following error message:

    Cannot call member function 'QModelIndexList QItemSelectionModel::selectedRows(int) const' without object
    Here is my code:
    Qt Code:
    1. myTable->setSelectionMode(QItemSelectionModel::selectedRows());
    To copy to clipboard, switch view to plain text mode 

    Many thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Selecting somes cells from a QTableWidget

    There are two errors in your code

    1) setSelectionMode takes a value of the QAbstractItemView::SelectionMode enum, not a list of model indexes
    2) QItemSelectionModel::selectedRows() is an instance method, it needs to be called on an instance of QItemSelection model. That is also what the compiler tells you

    Cheers,
    _

  3. #3
    Join Date
    Jan 2012
    Posts
    83
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Selecting somes cells from a QTableWidget

    Many thanks Anda_Skoa for your reply.

    I have modified the code as followed, but even if I deselect some cells, I still have their data.

    Qt Code:
    1. myTableau->setSelectionMode(QAbstractItemView::MultiSelection);
    To copy to clipboard, switch view to plain text mode 

    What am I doing wrong?

    Many thanks!

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Selecting somes cells from a QTableWidget

    I am not sure what you mean. The selection does not affect any data, it is just visualization.

    Cheers,
    _

  5. #5
    Join Date
    Jan 2012
    Posts
    83
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Selecting somes cells from a QTableWidget

    The selection does not affect any data, it is just visualization.
    Yes Anda_skoa, you are wright. It is just vusualization.

    A click on the name of my column select all cells of this column, and marks them blue. If I have rows on my table, how to tell the code that I just want data from rows 1, 3 and 5 for example?

    Many thanks!

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Selecting somes cells from a QTableWidget

    The first argument of the item() method is the row.
    Get the item for each cell you are interested in and read its data.

    Cheers,
    _

  7. #7
    Join Date
    Jan 2012
    Posts
    83
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Selecting somes cells from a QTableWidget

    Thanks Anda_Skoa for your reply.

    I am using a loop to accees the cells of my column.
    I have added the following condition in my loop:

    Qt Code:
    1. QTableWidgetItem *valueOfMycell;
    2. if(valueOfMyCell->isSelected())
    3. {
    4. }
    To copy to clipboard, switch view to plain text mode 

    The output (from qDebug) ist excatly the values I am looking for, but the program crasches down.
    When I removed the line 2, I have all values of my culumn, including those deselected.
    I now know that the condition of the line 2 is not appropriate, but I am wondering if there is another condition which matches with this case.
    I would appreciate any help.

    Many thanks in advance.

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Selecting somes cells from a QTableWidget

    The condition looks good, it is more likely that you have an error elsewhere, especially if "the program crashes down" means it unexpectedly terminates.

    Alternatively look at QTableWidget::selectedItems() to directly get the selected cells.

    Cheers,
    _

  9. #9
    Join Date
    Jan 2012
    Posts
    83
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Selecting somes cells from a QTableWidget

    Many thanks Anda_Skoa for your help.

    I have successfully fixed the problem using QTableWidget::selectedItems() as you have specified.

    For me is this problem solved.

    Many thanks one more time.

Similar Threads

  1. QTableWidget exclusive cells
    By bwnicewo in forum Qt Programming
    Replies: 1
    Last Post: 30th May 2012, 00:25
  2. How to display cut cells in QTableWidget
    By danblanks in forum Qt Programming
    Replies: 0
    Last Post: 16th February 2011, 21:42
  3. [How to ?] Writing QTableWidget cells.
    By Rewo in forum Newbie
    Replies: 6
    Last Post: 4th April 2010, 11:00
  4. Merging cells in QTableWidget
    By lyucs in forum Newbie
    Replies: 1
    Last Post: 22nd January 2010, 19:15
  5. Focus of cells in a QTableWidget
    By SailinShoes in forum Qt Programming
    Replies: 4
    Last Post: 9th June 2008, 08:19

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.