QTableWidgetItem *temp = new ::QTableWidgetItem;temp->setCheckState(Qt::Checked);ui->tableWidget->setItem(1,1,temp);
connect(temp, SIGNAL(toggled(bool)), MainWindow, SLOT(close()));
C++ (Qt)void QTableWidget::itemChanged ( QTableWidgetItem * item );
C++ (Qt)#ifndef MAINWINDOW_H#define MAINWINDOW_H #include <QtGui/QMainWindow>#include <QtGui/QTableWidgetItem>#include <QtGui/QMessageBox> namespace Ui{ class MainWindow;} class MainWindow : public QMainWindow{ Q_OBJECT public: MainWindow(QWidget *parent = 0); ~MainWindow(); private: Ui::MainWindow *ui; void check( QTableWidgetItem * ); }; #endif // MAINWINDOW_H
C++ (Qt)#include "mainwindow.h"#include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ ui->setupUi(this); ui->tableWidget->setColumnWidth(0,150); ui->tableWidget->setRowCount(2); QTableWidgetItem *temp = new QTableWidgetItem; temp->setCheckState(Qt::Checked); ui->tableWidget->setItem(1,1,temp); MainWindow::check(temp); } MainWindow::~MainWindow(){ delete ui;} void MainWindow::check(QTableWidgetItem *temp){ if ( temp->checkState() == Qt::Unchecked ) QMessageBox::warning(this, QString::fromLocal8Bit("test"), QString::fromLocal8Bit("test"));}
C++ (Qt)QObject::connect(ui->tableWidget, SIGNAL(itemClicked(QTableWidgetItem*)), MainWindow, SLOT(check()));
C++ (Qt)...QObject::connect(ui->tableWidget, SIGNAL(itemClicked(QTableWidgetItem*)), this, SLOT(check()));...
C++ (Qt)MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ ui->setupUi(this); ui->tableWidget->setColumnWidth(0,150); ui->tableWidget->setRowCount(2); QTableWidgetItem *temp = new QTableWidgetItem; temp->setCheckState(Qt::Checked); ui->tableWidget->setItem(1,1,temp); QObject::connect(ui->tableWidget, SIGNAL(itemClicked(QTableWidgetItem*)), this, SLOT(check(temp)));} MainWindow::~MainWindow(){ delete ui;} void MainWindow::check(QTableWidgetItem *temp){ if ( temp->checkState() == Qt::Checked ) QMessageBox::warning(this, QString::fromLocal8Bit("test"), QString::fromLocal8Bit("test"));}
C++ (Qt) QObject::connect(ui->tableWidget, SIGNAL(itemClicked(QTableWidgetItem*)), this, SLOT(check(QTableWidgetItem*)));
C++ (Qt)...private slots: void check( QTableWidgetItem * );...