c++ - QT: Scrolling 2 QPlainTextEdits at the same time -


i want create internal tool usage 2 qplaintextedits. want make functionality when scroll 1 text edit other scrolled also. tried figure out http://doc.qt.io/qt-4.8/qt-widgets-codeeditor-example.html not work expected

here code:

customedit.h

#ifndef customedit_h #define customedit_h  #include <qplaintextedit>  class customedit : public qplaintextedit {     q_object public:     customedit(qwidget *parent = 0);  public slots:     void updateposition(const qrect &, int); };  #endif // customedit_h 

customedit.cpp

#include "customedit.h"  customedit::customedit(qwidget *parent) : qplaintextedit(parent) {  }  void customedit::updateposition(const qrect &rect, int position) {      if (position) {         this->scroll(0, position);         this->update(0, rect.y(), this->width(), rect.height());     }     else {         this->update(0, rect.y(), this->width(), rect.height());     }  } 

mainwindow constructor

mainwindow::mainwindow(qwidget *parent) :     qmainwindow(parent),     ui(new ui::mainwindow) {     ui->setupui(this);      printoutanalyzer = new printoutanalyzer();      ui->log->setreadonly(true);     ui->progress->reset();      resultedit = new customedit(this);     printoutedit = new customedit(this);      resultedit->setreadonly(true);     printoutedit->setreadonly(true);      ui->horizontallayout->addwidget(printoutedit);     ui->horizontallayout->addwidget(resultedit);       connect(printoutanalyzer, signal(writetolog(qstring)), this, slot(putlogtext(qstring)));     connect(printoutanalyzer, signal(writetoresult(qstring)), this, slot(putresulttext(qstring)));     connect(printoutanalyzer, signal(setprogress(int)), this, slot(setprogress(int)));     connect(ui->loadprintout, signal(triggered()), this, slot(chooseprintoutfile()));      connect(printoutedit, signal(updaterequest(qrect, int)), resultedit, slot(updateposition(qrect, int)));     connect(resultedit, signal(updaterequest(qrect, int)), printoutedit, slot(updateposition(qrect, int))); } 

when execute code , scroll 1 text edit second 1 looks (text edits have same content):

fault example

the simple keep vertical scrollbars of qplaintextedit in sync of ''sliderposition property''.


Comments

Popular posts from this blog

How to get the arclen between two curve points in Maya? -

git svn - Unignore directories in git-svn (adding directories to a sparse checkout) -

C++ Linked List -