dentist
13th April 2010, 13:23
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;
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;
}
};
It's quite the same implementation as introduced here (http://qt.nokia.com/developer/faqs/faq.2007-06-08.0800842041), 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 ?
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;
}
};
It's quite the same implementation as introduced here (http://qt.nokia.com/developer/faqs/faq.2007-06-08.0800842041), 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 ?