#include <QtGui>
{
Q_OBJECT
public:
TableWidget
(int rows,
int cols
) : QTableWidget(rows, cols
) {}public slots:
QList<QTableWidgetItem *> list = findItems(item->text(),Qt::MatchExactly);
QModelIndex index
=model
()->index
(foundItem
->row
(), foundItem
->column
());
}
};
#include "main.moc"
int main(int argc, char *argv[])
{
TableWidget tableWidget2(100, 10);
for(int i=0;i<100;++i)
tableWidget1.show();
tableWidget2.show();
return a.exec();
}
#include <QtGui>
class TableWidget : public QTableWidget
{
Q_OBJECT
public:
TableWidget(int rows, int cols) : QTableWidget(rows, cols) {}
public slots:
void findItem(QTableWidgetItem *item, QTableWidgetItem */* */){
QList<QTableWidgetItem *> list = findItems(item->text(),Qt::MatchExactly);
QTableWidgetItem *foundItem = list[0];
QModelIndex index =model()->index(foundItem->row(), foundItem->column());
scrollTo(index, QAbstractItemView::PositionAtCenter);
}
};
#include "main.moc"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTableWidget tableWidget1(3, 1);
tableWidget1.setItem(0,0,new QTableWidgetItem("Item #1"));
tableWidget1.setItem(1,0,new QTableWidgetItem("Item #50"));
tableWidget1.setItem(2,0,new QTableWidgetItem("Item #89"));
TableWidget tableWidget2(100, 10);
for(int i=0;i<100;++i)
tableWidget2.setItem(i, qrand() % 10, new QTableWidgetItem(QString("Item #%1").arg(i+1)));
QObject::connect(&tableWidget1, SIGNAL(currentItemChanged(QTableWidgetItem*,QTableWidgetItem*)),&tableWidget2, SLOT(findItem(QTableWidgetItem*,QTableWidgetItem*)));
tableWidget1.show();
tableWidget2.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks