Hi, i have a scrolling issue. I read lots of docs, googled, etc - but couldn't figure it out. The idea is to scroll 2 QGraphicsViews with the scrollbar of one of them. This is what i did:
class QPianoRoll
: public QWidget {
Q_OBJECT
public:
QPianoRoll(){
currentScrollPosition = 0;
// both, QNoteEditor and QVerticalPiano are derived from QGraphicView
piano = new QVerticalPiano();
layout->addWidget(piano);
QNoteEditorCore * editor = new QNoteEditorCore();
wrapper = new QNoteEditor(editor);
QScrollBar * scrollbar
= wrapper
->verticalScrollBar
();
connect(scrollbar, SIGNAL(valueChanged(int)),this,SLOT(scrollRoll(int)));
layout->addWidget(wrapper,2);
layout->setAlignment(Qt::AlignLeft);
setLayout(layout);
}
private :
QNoteEditor * wrapper;
QVerticalPiano * piano;
int currentScrollPosition;
public slots :
void scrollRoll(int value) {
int relative = currentScrollPosition - value;
piano->scroll(0,relative);
currentScrollPosition = value;
}
};
class QPianoRoll : public QWidget {
Q_OBJECT
public:
QPianoRoll(){
currentScrollPosition = 0;
QHBoxLayout *layout = new QHBoxLayout;
// both, QNoteEditor and QVerticalPiano are derived from QGraphicView
piano = new QVerticalPiano();
layout->addWidget(piano);
QNoteEditorCore * editor = new QNoteEditorCore();
wrapper = new QNoteEditor(editor);
QScrollBar * scrollbar = wrapper->verticalScrollBar();
connect(scrollbar, SIGNAL(valueChanged(int)),this,SLOT(scrollRoll(int)));
layout->addWidget(wrapper,2);
layout->setAlignment(Qt::AlignLeft);
setLayout(layout);
}
private :
QNoteEditor * wrapper;
QVerticalPiano * piano;
int currentScrollPosition;
public slots :
void scrollRoll(int value) {
int relative = currentScrollPosition - value;
piano->scroll(0,relative);
currentScrollPosition = value;
}
};
To copy to clipboard, switch view to plain text mode
It's quite the same implementation as introduced here, but unfortunately it doesn't work. The slot scrollRoll just moves the visible scene up and down and does not scroll any contents. What am I doing wrong ?
Bookmarks