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. How to get widget within cell of QTableWidget to pass focus to the QTableWidget?
QtWS25 Last Chance

How to get widget within cell of QTableWidget to pass focus to the QTableWidget?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 9.9k Views
  • 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.
  • T Offline
    T Offline
    Tiwilager
    wrote on 6 Jun 2011, 19:38 last edited by
    #1

    I'm setting a cell in QTableWidget to another widget like so:

    @
    QSpinBox* widget = new QSpinBox();
    widget->setValue(1);
    widget->setRange(1, 255);
    widget->setSingleStep(1);
    ui->tableWidget->setCellWidget(row, col, widget);
    @

    but when I click on that widget, the QTableWidget does not update to the current cell.

    EDIT: please use @-tags for code highlighting, Gerolf

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tdmatsu
      wrote on 6 Jun 2011, 20:38 last edited by
      #2

      I'm not sure if I understood your expectations. What do you mean by "QTableWidget does not update to the current cell"?

      Also, what are row and col supposed to be in your code?

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Tiwilager
        wrote on 6 Jun 2011, 22:16 last edited by
        #3

        row and col are just place holders for this example.

        When I click on the spinbox, the QTableWidget does not recognize that I clicked within it. I can change the spinbox fine, but when I try to get the current cell from the TableWidget, I just get -1, which is no cell selected.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on 7 Jun 2011, 05:49 last edited by
          #4

          Sure, why should the table be changed? you did not connect the spin box with the table. If you use cell widgets, that's up to you to update the content of the table.

          If not a permanent widget is needed, I suggest you use a "delegate":http://doc.qt.nokia.com/4.7/model-view-programming.html#delegate-classes . A delegate can be used to create the cell editors, once the user starts editing a cell. Those values are then stored in the corresponding data model (it's part of the QTableWidget).

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sigrid
            wrote on 7 Jun 2011, 06:13 last edited by
            #5

            The following "FAQ":http://developer.qt.nokia.com/faq/answer/how_can_i_get_hold_of_a_cell_widgets_row explains how you can get hold of a cell widget's row and column information. Does it provide you the information you are looking for?

            1 Reply Last reply
            0

            1/5

            6 Jun 2011, 19:38

            • Login

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