Qt World Summit: Submit your Presentation

How to throw cell click event of QTable Widget

  • Hi All

    I have created one QTableWidget.
    I have one function in which I am performing some operations.
    When this operation is successfull I want the CellClick event on first row of Table.
    How to do this?

  • Please rephrase your question. There is no CellClick event that can be on a row or something like that.

  • Hi Andre

    I mean to say cell click for (0,0)Cell in the Table widget.

  • Do I understand correctly:

    You want to have some function like this:

    <whatever type> foo()
    // do some work here
    // simulate a mouse click event on a specific cell of a table
    // do something else

  • Yes Gerolf.

  • What about setCurrentItem()?

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

    What is the use case?

  • 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.

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

    @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


    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(QString text){

    Hope it helps you!

  • 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.

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


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

  • Hi Iktwo

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

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

  • So putting it together:

    setFocus for the table

    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.

  • 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
    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.

  • 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.

Log in to reply