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 throw cell click event of QTable Widget
Forum Updated to NodeBB v4.3 + New Features

How to throw cell click event of QTable Widget

Scheduled Pinned Locked Moved General and Desktop
16 Posts 5 Posters 17.9k 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.
  • I Offline
    I Offline
    Indrajeet
    wrote on last edited by
    #5

    Yes Gerolf.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #6

      What about setCurrentItem()?

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #7

        Why do you want to emulate a click?
        to set the input focus?
        to start editing a cell?

        What is the use case?

        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
        • I Offline
          I Offline
          Indrajeet
          wrote on last edited by
          #8

          Hi Gerolf

          On the click of the particular cell I am reading the data of that row.
          So By default i want to read the data of 1st row.
          code to read the data is implemented in the SLOT of cell click.

          1 Reply Last reply
          0
          • I Offline
            I Offline
            Iktwo
            wrote on last edited by
            #9

            Hi, I I did something similar with QTableWidget and I used cell clicked signal

            (http://doc.qt.nokia.com/latest/qtablewidget.html)
            @void cellClicked ( int row, int column )@

            if I understand you correctly you want to trigger the signal for the a particular cell (in the first post you said row, it may have confused some) if you have connected the signal and slot, you should be able to call the slot with row 1 and column 1.

            I have something like this

            @void VenVisReservaciones::on_tblReservaciones_cellClicked(int row, int column){
            ..
            }@

            So if I finish processing data I do something like this

            @
            on_tblReservaciones_cellClicked(1,1);
            @

            If you want to click a cell and then you want to read the first cell of that row, then you can do something like this:

            @void VenVisReservaciones::on_tblReservaciones_cellClicked(int row, int column){
            process(ui->tblReservaciones->item(1,row)->text());
            ..
            }

            process(QString text){
            ..
            }
            @

            Hope it helps you!

            1 Reply Last reply
            0
            • I Offline
              I Offline
              Indrajeet
              wrote on last edited by
              #10

              Hi IKtwo

              Thanks it worked.
              But now I also want the focus to be on 1st row[i.e it should show as 1st row is selected]
              How to do that.

              1 Reply Last reply
              0
              • I Offline
                I Offline
                Iktwo
                wrote on last edited by
                #11

                I'm not sure if a Cell has a method called setFocus(), you can try it, something like

                @ui->table->item(X,Y)->setFocus();@

                If that doesn't work maybe @setSelected(true)@

                1 Reply Last reply
                0
                • I Offline
                  I Offline
                  Indrajeet
                  wrote on last edited by
                  #12

                  Hi Iktwo

                  setSelected(true)
                  is working but it is not removing selection of previous row.
                  Here user gets a feel of two are selected .

                  1 Reply Last reply
                  0
                  • I Offline
                    I Offline
                    Iktwo
                    wrote on last edited by
                    #13

                    Sorry for that, maybe @void setCurrentCell ( int row, int column )@

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      giesbert
                      wrote on last edited by
                      #14

                      So putting it together:

                      setFocus for the table
                      setCurrentCell()

                      in combination should set the current cursor position to the specified cell.

                      If you want to clean any selection before, do it via the selectionModel.

                      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
                      • I Offline
                        I Offline
                        Indrajeet
                        wrote on last edited by
                        #15

                        Hi Gerolf

                        Its not working,I m doing something like this
                        @
                        on_AE_Tablecell_Clicked(0,0);//This is the slot i want to be called
                        ui.tableWidget_AE->setCurrentCell(0,0,QItemSelectionModel::Rows);
                        @
                        By doing this it only setting the focus to (0,0) item but i want to show that complete row as blue and other previous selection should be removed.

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          goetz
                          wrote on last edited by
                          #16

                          selectRow(0) is the slot to use.

                          You could have found yourself very easily if you had scanned through the fine API documentation of [[Doc:QTableWidget]] and its base classes [[Doc:QTableView]] and [[Doc:QAbstractItemView]]. Finding that slot with a quick search in the browser is a no brainer.

                          http://www.catb.org/~esr/faqs/smart-questions.html

                          1 Reply Last reply
                          0

                          • Login

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