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. Mapping Cell QPushbutton to the other cell in QTableWidget
Forum Updated to NodeBB v4.3 + New Features

Mapping Cell QPushbutton to the other cell in QTableWidget

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.7k 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.
  • E Offline
    E Offline
    eyesBird
    wrote on last edited by
    #1

    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();
    

    }@

    1 Reply Last reply
    0
    • D Offline
      D Offline
      D0IT
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • E Offline
        E Offline
        eyesBird
        wrote on last edited by
        #3

        i will try ....
        thanks..

        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