Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved] Synchronizing two QTableView's scrollbars
Forum Updated to NodeBB v4.3 + New Features

[solved] Synchronizing two QTableView's scrollbars

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 7.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jj8431
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    1
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      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).

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jj8431
        wrote on last edited by
        #3

        Oh thank you ChrisW67, it's it! I included <QScrollBar> and then everything's ok.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved