Mapping Cell QPushbutton to the other cell in QTableWidget



  • Hi Qt Warrior

    i have 3 row and 3 column on the QTablewidget
    on the third row i put Qpushbutton (detailButton) on it.
    now i am finished create signal and slot to call the spesific row and column
    but my problem is each i click the detail button its not match the row and the column.

    here my code:

    @void MainWindow::Viewtable()
    {

    table = new QTableWidget();
    table->setWindowTitle("Input Data Result");
    
    
    
    
    
    QSqlQuery query("SELECT * FROM employee");
    table->setColumnCount(5);
    //query.record().count() cara mengambil jumlah column di database
    //untuk membuat table secara auto seperti table database
    
    table->setRowCount(query.size());
    
    
    
    int index=0;
    while (query.next())
    {
    
        CellCeckbok = new QCheckBox("Check",this);
        CheckbokLayout = new QHBoxLayout();
        CheckbokLayout->addSpacerItem(new QSpacerItem(5,1));
        CheckbokLayout->addWidget(CellCeckbok);
        CheckbokWidget = new QWidget();
        CheckbokWidget->setLayout(CheckbokLayout);
    
    
       // buttonItem = QTableWidgetItem();
    
    
        buttonEdit=new QPushButton("Edit",this);
        buttonDetail=new QPushButton("Detail",this);
    

    // buttonDetail->setData(index,0);

        horiCellLayout= new QHBoxLayout();
        horiCellLayout->addWidget(buttonEdit);
        horiCellLayout->addWidget(buttonDetail);
    
        widgetCell= new QWidget();
        widgetCell->setLayout(horiCellLayout);
    table->setHorizontalHeaderLabels(QString("id  ; Name  ; Salary ; Option").split(";"));
    table->verticalHeader()->hide();
    table->setItem(index,0,new QTableWidgetItem(query.value(0).toString()));
    table->setItem(index,1,new QTableWidgetItem(query.value(1).toString()));
    table->setItem(index,2,new QTableWidgetItem(query.value(2).toString()));
    table->setCellWidget(index,3,widgetCell);
    /*Special Connection****/
    connect(buttonDetail,SIGNAL(clicked(bool)),this,SLOT(getText()));
    /*****************/
    
    
    table->setRowHeight(index,42);
    table->setColumnWidth(3,250);
    table->setCellWidget(index,4, CheckbokWidget);
    
    //table->insertRow(row);
    
    //qDebug()<< row;
    
    
    
    
    
    
    
    index++;
    
    }
    
    
    
    
    table->show();
    

    }
    @

    my slot function
    @void MainWindow::getText()// Detail Button
    {

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

    }@



  • You can use a "QSignalMapper":http://qt-project.org/doc/qt-4.8/qsignalmapper.html#details to connect the clicked signal from the buttons and map the cell information for you getText slot.



  • i will try ....
    thanks..


Log in to reply
 

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