Get Text from QTableWidget in spesific row and colum



  • Hi All,
    I have a QTableWidget and put a Detail Button on cell QTableWidget
    how to get The spesific row and column while i click The Button Detail in the cell QTableWidget

    what I can do right now is Retrive the Text using qDebug:

    @ for (int i=0; i<table->rowCount(); ++i)
    {

        qDebug()<< table->item(i, 0)->text();
        qDebug() << table->item(i, 1)->text();
        qDebug() << table->item(i, 2)->text();
    }
    

    @



  • First you can get Current Index
    @
    QModelIndex currentIndex = table->currentIndex();
    @
    than you can do
    @
    //For Column 0.
    qDebug() << table->item(currentIndex.row(), 0)->text();
    //For Column 1.
    qDebug() << table->item(currentIndex.row(), 1)->text();
    @
    I hope this will work. Because when you click the Detail Button than that row will be the current index.



  • anyway i have try to do that, but its still not working

    signal and slot:
    @connect(buttonDetail,SIGNAL(clicked(bool)),this,SLOT(getText()));
    @

    and my function slot:
    @void MainWindow::getText()// Detail Button
    {
    QModelIndex curentIndex = table->currentIndex();

    qDebug() << table->item(curentIndex.row(), 0)->text();
    qDebug() << table->item(curentIndex.row(), 1)->text();
    

    }

    @



  • Please make sure that getText() Slot is invoked while you click on the button. :) As i have told the currentIndex() gives the row and col of currently focused row so that when you are clicking on the button means u should have focus on that button :)



  • Thanks
    i wiil make sure of that


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.