#include <QtGui>
#include <QApplication>
{
Q_OBJECT
public:
{
connect(table, SIGNAL(cellDoubleClicked(int, int)), this, SLOT(tableChangeDbl(int, int)));
connect(table, SIGNAL(cellClicked(int, int)), this, SLOT(tableChange(int, int)));
table->setContextMenuPolicy(Qt::CustomContextMenu);
connect(table,
SIGNAL(customContextMenuRequested
(const QPoint &)),
this,
SLOT(PopupMenuTableShow
(const QPoint &)));
show();
}
public slots:
void tableChange(int row, int column)
{
append
(QString("Clicked %1, %2").
arg(row
).
arg(column
));
}
void tableChangeDbl(int row, int column)
{
append
(QString("Double Clicked %1, %2").
arg(row
).
arg(column
));
}
void PopupMenuTableShow
(const QPoint & point
) {
append
(QString("Menu %1, %2").
arg(point.
x()).
arg(point.
y()));
}
};
int main(int argc, char **argv)
{
Widget widget(&tableWidget);
tableWidget.setRowCount(10);
tableWidget.setColumnCount(2);
for(int r = 0 ; r < tableWidget.rowCount(); r++)
for(int c = 0 ; c < tableWidget.columnCount(); c++)
tableWidget.setWindowTitle("QTableWidget");
widget.setWindowTitle("Widget");
tableWidget.show();
widget.show();
return app.exec();
}
#include "main.moc"
#include <QtGui>
#include <QApplication>
class Widget : public QTextBrowser
{
Q_OBJECT
public:
explicit Widget(QTableWidget * table)
: QTextBrowser(0)
{
connect(table, SIGNAL(cellDoubleClicked(int, int)), this, SLOT(tableChangeDbl(int, int)));
connect(table, SIGNAL(cellClicked(int, int)), this, SLOT(tableChange(int, int)));
table->setContextMenuPolicy(Qt::CustomContextMenu);
connect(table, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(PopupMenuTableShow(const QPoint &)));
show();
}
public slots:
void tableChange(int row, int column)
{
append(QString("Clicked %1, %2").arg(row).arg(column));
}
void tableChangeDbl(int row, int column)
{
append(QString("Double Clicked %1, %2").arg(row).arg(column));
}
void PopupMenuTableShow(const QPoint & point)
{
append(QString("Menu %1, %2").arg(point.x()).arg(point.y()));
}
};
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QTableWidget tableWidget;
Widget widget(&tableWidget);
tableWidget.setRowCount(10);
tableWidget.setColumnCount(2);
for(int r = 0 ; r < tableWidget.rowCount(); r++)
for(int c = 0 ; c < tableWidget.columnCount(); c++)
tableWidget.setItem(r, c, new QTableWidgetItem(QString("%1:%2").arg(r).arg(c)));
tableWidget.setWindowTitle("QTableWidget");
widget.setWindowTitle("Widget");
tableWidget.show();
widget.show();
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks