M
M
meteorkaaa2020-05-27 16:45:14
Qt
meteorkaaa, 2020-05-27 16:45:14

How to make a confirm button for delete all rows operation of QTWidgets?

I wanted to implement the function of deleting all rows in the database in my program, how to contact the main window through the confirmation window so that it deletes all rows?

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "warningwindow.h"
#include <QTableWidget>
#include <QMessageBox>
#include <QDialog>
#include <QWidget>
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->tableWidget->setRowCount(6);
    ui->tableWidget->setColumnCount(7);
    int count=1;
    for(int i=0; i<ui->tableWidget->rowCount();i++) //строка
        for(int j=1;j<4;j++) //столбец
        {
            QTableWidgetItem *itm=new QTableWidgetItem(tr("%1").arg(count));
            ui->tableWidget->setItem(i,j,itm);
            count ++;
        }

    /*for  (int b=0; b<ui->tableWidget->rowCount();b++);
       for(int c=1;c<2;c++)
    {
    QTableWidgetItem *pl=new QTableWidgetItem(tr("%1").arg(count));

    }*/
}

MainWindow::~MainWindow()
{
    delete ui;

}
void MainWindow::on_pushButton_2_clicked()
{
   ui->tableWidget->insertRow( ui->tableWidget->rowCount() );
}

void MainWindow::on_pushButton_3_clicked()
{
   ui->tableWidget->removeRow(ui->tableWidget->currentRow());
}

void MainWindow::on_pushButton_clicked()
{
    ui->tableWidget->edit(ui->tableWidget->currentIndex());
}

void MainWindow::on_pushButton_4_clicked()
{
warningwindow window;
window.setModal(true);
window.exec();
    //ui->tableWidget->setRowCount(0);
}


#include "warningwindow.h"
#include "ui_warningwindow.h"
#include "mainwindow.h"
warningwindow::warningwindow(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::warningwindow)
{
    ui->setupUi(this);
}

warningwindow::~warningwindow()
{
    delete ui;
}

void warningwindow::on_buttonBox_accepted()
{
}

void warningwindow::on_buttonBox_rejected()
{
    close();

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Ananiev, 2020-05-27
@meteorkaaa

You create a modal question dialog, then see what the user clicked (the result of the dialog) and execute the necessary code based on the result.
Is this what you need?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question