PDA

View Full Version : ScrollBar is not moving properly when I use TAB



chikkireddi
16th May 2007, 17:55
Hi

In my application, multiple of QLineEdit widgets are added to Vertical List(QVBoxLayout). I also enabled Vertical Scroll Bar.

Please see attached jpeg file image. I would like to know how to solve this kind of problems.

Thanks
C V rao

wysota
16th May 2007, 17:58
Do you use a scroll area or something like that? Could you provide more details?

chikkireddi
16th May 2007, 22:29
Yes I used ScrollArea and set the properties to scroll area

m_scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOf f);
m_scrollArea->setWidgetResizable(true);
m_scrollArea->setLineWidth(0);
m_scrollArea->setFixedHeight(191);
m_scrollArea->setWidget(emailVListArea);
m_scrollArea->setFixedSize(780,191);
no_pixestoJump = TOP_SPACING + fromLabel->size().height() + (BUTTON_HEIGHT - EMAILAPP_BUTTON_HEIGHT) + fromEditBox->size().height()
m_scrollArea->verticalScrollBar()->setSingleStep(no_pixestoJump);


If I use mouse, scroll bar moving correctly means jumping no_pixestoJump up or down.
When I use TAB same thing is not happen, it is moving incorrectly...

wysota
16th May 2007, 23:04
Why should it scroll if you use tab?

chikkireddi
17th May 2007, 00:20
My question is Children widgets of ScrollArea is not shown properly when I use TAB.

wysota
17th May 2007, 09:28
Did you implement that somehow? What about the tab order, does it work?

chikkireddi
18th May 2007, 23:01
Tab order is working fine.
If I press Vertical Scroll Bar Up/Down buttons, Scroll Area Filelds are moving X pixes Up/Down , X is an integer argument passed to verticalScrollBar()->setSingleStep(X).

But When I use Tab ,the child widgets of scroll area are not shown properly.

Exmple: I have 7 QLineEdit widgets in my scroll area. let say Scroll Area can hold only 5 QLineEdit widgets at any time.

When I use Tab focus come to 1 st QLineEdit
Again Tab, focus come to 2nd QLineEdit
Again Tab, focus come to 3rd QLineEdit
Again Tab, focus come to 4th QLineEdit
Again Tab, focus come to 5th QLineEdit
Till this point Childwidgets are not moved up. This is correct as ScrollAre hold 5 LineEdits Widgets.

Again Tab, focus come to 6th QLineEdit.
Expected Behaviour: First QLineEdit is showing half.
Wanted Behaviour : First QlineEdit should go up fully. 2,3,4,5,6 QlineEdit widgets should show.

How do I implement the above wanted behaviour?

Thanks
C V Rao

wysota
19th May 2007, 00:52
QScrollArea::ensureWidgetVisible

chikkireddi
21st May 2007, 17:11
I use above function like this,

m_scrollArea->ensureWidgetVisible(QLineEdit,100,100);

No effect in GUI behavioour....

How Do I use, this function QScrollArea::ensureWidgetVisible. Do I need check everytime?

wysota
21st May 2007, 20:10
Do you need to check what? When you want a particular widget to be visible, just call this method with appropriate parametres.

marcel
21st May 2007, 20:33
I use above function like this,

m_scrollArea->ensureWidgetVisible(QLineEdit,100,100);

No effect in GUI behavioour....

How Do I use, this function QScrollArea::ensureWidgetVisible. Do I need check everytime?

Are you sure the widget is a direct child of the scroll area?

chikkireddi
22nd May 2007, 16:31
The hierarchy is as follows.

QLineEdit is added to QBoxVLayout
QBoxVLayout is added to QWidget
QWidget is added QScrollArea.


So QLineEdit is child of QScrollArea.

When I use Tab, then it should call ensureWidgetVisible(). How can I implement this?

Thanks and Regards
C V Rao

marcel
22nd May 2007, 17:27
ensureWidgetVisible will not work because the line edit is not a direct child.
Use ensureVisible instead and pass the pos of the line edit. The position of the line edit is available from QWidget::geometry().

The item that must be visible is the one that has the focus, so you probably have to iterate through all the children in the widget from the scroll area to find the lie edit that has the focus.

Regards

jpn
22nd May 2007, 17:42
I don't know what's the actual problem here because QScrollArea already does ensure the child widget becomes visible:


/*!
\reimp
*/
bool QScrollArea::focusNextPrevChild(bool next)
{
if (QWidget::focusNextPrevChild(next)) {
if (QWidget *fw = focusWidget())
ensureWidgetVisible(fw);
return true;
}
return false;
}


Subclass QScrollArea and reimplement focusNextPrevChild() to fine tune scroll bar values if you're not happy with the default behaviour.

marcel
22nd May 2007, 18:24
I take back what I said :)
The scroll area knows if it is an ancestor of the line edit.
So the problem could be that you do not parent the widgets correctly.

Could you debug ensureWidgetVisible?
Or, at least see what scrollarea->widget()->isAncestorOf( lineEdit ) returns.


Regards

chikkireddi
25th May 2007, 22:30
scrollarea->widget()->isAncestorOf( lineEdit ) is returning true.

I tries to subclass ScrollArea, but I got many compilation error as we are inherting this class from our own classes.

Thanks
cvrao