Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTableWidget Programmatically Select Cells
Forum Updated to NodeBB v4.3 + New Features

QTableWidget Programmatically Select Cells

Scheduled Pinned Locked Moved Solved General and Desktop
qtablewidgetcellselectslotssignals
3 Posts 2 Posters 8.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    oblivioncth
    wrote on 4 Apr 2016, 22:01 last edited by oblivioncth 4 Apr 2016, 22:01
    #1

    Hello,

    I currently have a QTableWidget setup with 5 rows and 3 columns and only the cells under column 1 are delectable. I have a slot:

    void MainWindow::on_imgTable_cellClicked(int row, int column)
    

    which makes it so when a cell in that column is selected a corresponding image is displayed in a separate QLabel widget. This works totally fine.

    However, column 0 contains buttons that when clicked either add an image path or remove one into a variable, depending on if one was there or not already. It is these images that are previewed when the cells in the column 1 are selected. I want to add the additional functionality so that when you click one of the buttons in column 0 to add an image, its corresponding cell in column 1 is automatically selected as if the user had clicked on it and that slot above is triggered (again as if the user had actually clicked the cell).

    I checked through the documentation and tried using "QAbstractItemView::setCurrentIndex() " and something like:

    select(TABLEWIDG->model()->index(row,colum), QItemSelectionModel::Select);
    

    but in both cases the cell is "selected" with a dull grey color that is barely distinguishable from the white and the slot is not activated. So, how can I have the cell programmatically selected with the typical blue highlight as if the user had clicked it and have the cells "clicked()" slot trigger? I am assuming I can just call the slot if having it trigger without the user actually clicking the cell isn't possible. If that is the case I just need to know how to get it to appear selected with the standard blue highlight.

    Thank you.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 4 Apr 2016, 22:15 last edited by
      #2

      Hi,

      IIRC, you should set the focus on the QTableWidget so it makes it the active widget.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      O 1 Reply Last reply 4 Apr 2016, 22:44
      1
      • S SGaist
        4 Apr 2016, 22:15

        Hi,

        IIRC, you should set the focus on the QTableWidget so it makes it the active widget.

        O Offline
        O Offline
        oblivioncth
        wrote on 4 Apr 2016, 22:44 last edited by
        #3

        @SGaist

        Thank you. That seemed to be the last missing piece. It does what I want now.

        1 Reply Last reply
        0

        3/3

        4 Apr 2016, 22:44

        • Login

        • Login or register to search.
        3 out of 3
        • First post
          3/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved