PDA

View Full Version : qscrollarea slider problem



babu198649
22nd November 2007, 05:31
hi
i have a qlabel whose parent is qscrollarea. i have subclassed the qlabel to receive mouse move events.

whwnever the label(contains image) is moved using mouse (click and then move)
the label inside qscrollarea moves. but the scrollbars are not moving with respect to qlabel.

how to update the scrollbars with respect to qlabel movement.

wysota
22nd November 2007, 10:15
Could we see some code? The event handler at least...

jpn
22nd November 2007, 12:14
You'll need a container widget which is the parent of the movable label. This container widget must automatically grow when label is moved outside its boundaries. This container widget is then set inside the scroll area with QScrollArea::setWidget(). However, there are certain problems with this approach I don't have time to explain right now. Save yourself some time and use QMdiArea with frameless sub windows. ;)

babu198649
22nd November 2007, 12:44
Could we see some code?
sure:)



void iv_isa::mousePressEvent ( QMouseEvent * event )
{
QPoint mouse_event_distance
mouse_event_distance = mapToParent(event->pos()) - this->pos();
}

void IV_label::mouseMoveEvent ( QMouseEvent * event )
{
this->move(mapToParent(event->pos()) - mouse_event_distance);
}

wysota
22nd November 2007, 12:51
Does the scroll area contain anything else or just the label? Because if it contains just the label, use QMdiArea as suggested. If it contains some other elements, use QGraphicsView.