[solved] Synchronizing two QTableView's scrollbars
-
Hi I have 2 QTableView widgets shared a same model, so I'd like to synchronize the two views, using tableView_2's vertical scrollbar to control both of the 2 table views. I hope I expressed it clear enough.
I got some error message from the compiler, which seems a bit strange for me.
this is my code:
@MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
model = new MemBlockModel(this);
bufData = new quint8[0x100];
for (int i=0; i<0x100; i++)
{
bufData[i]=i;
}
hexDelegate = new HexDelegate;
charDelegate = new CharDelegate;
model->setBlock(bufData, 0x100);
ui->tableView->setModel(model);
ui->tableView->setItemDelegate(hexDelegate);
ui->tableView_2->setModel(model);
ui->tableView_2->setItemDelegate(charDelegate);
ui->tableView->resizeRowsToContents();
ui->tableView_2->resizeRowsToContents();
ui->tableView->resizeColumnsToContents();
int width1 = ui->tableView->verticalHeader()->width();
for (int i=0; i<ui->tableView->model()->columnCount(); i++)
{
width1 += ui->tableView->columnWidth(i);
}
ui->tableView->setMinimumWidth(width1);
ui->tableView_2->resizeColumnsToContents();
int width2=0;
for (int i=0; i<ui->tableView_2->model()->columnCount(); i++)
{
width2 += ui->tableView_2->columnWidth(i);
}
ui->tableView_2->setMinimumWidth(width2);
QObject::connect(ui->tableView_2->verticalScrollBar(), SIGNAL(valueChanged(int)), ui->tableView->verticalScrollBar(), SLOT(setValue(int)));
// ui->statusBar->showMessage("Message shown for 10s",10000);
}MainWindow::~MainWindow()
{
delete charDelegate;
delete hexDelegate;
delete []bufData;
delete ui;
}@when compiling, an error message says:
/.../mainwindow.cpp:38: error: no matching function for call to ‘MainWindow::connect(QScrollBar*, const char*, QScrollBar*, const char*)’and there are further following notes as this:
/usr/include/qt4/QtCore/qobject.h:198: note: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
/usr/include/qt4/QtCore/qobject.h:198: note: no known conversion for argument 1 from ‘QScrollBar*’ to ‘const QObject*’Why a QScrollBar* can't be converted to const QObject* ? What is the problem in my code?
Thanks
-
Does your code include:
@
#include <QScrollBar>
@If not, the compiler cannot know that a QScrollBar is-a QObject and therefore assumes the pointers are not compatible. The code generated by uic will only include QTableView, which likely only results in a forward declaration of QScrollBar (via QAbstractScrollArea).