Phone contacts header label scrolling in/out
-
Hello,
i am trying to implement a phone contacts like scrolling, where you have one static letter label not moving until the next section is reached. Then this label should slowly scroll out until the new section label is at top.
This is what i have tried so far. Having a form file with a QWidget. In the widget i have a QScrollArea(content holding non-static labels and buttons in each section) and a QLabel(the static label that should stay on top).
I am processing the Gesture Event to check if the user moved the vertical scroll area. The following is the snippet of my gesture event:const int static_header_height = 40; const QPoint scroll_area_pos = m_ui->CalleeScrollArea->verticalScrollBar()->pos(); QLabel * header_label = qobject_cast<QLabel*>(m_ui->CalleeScrollArea->childAt(scroll_area_pos)); QPushButton * callee_button = qobject_cast<QPushButton*>(m_ui->CalleeScrollArea->childAt(scroll_area_pos)); const bool is_header_at_top = header_label != nullptr;; if(is_header_at_top) { const int header_label_height = header_label->height(); const int visible_header_label_height = header_label->visibleRegion().boundingRect().height(); const int header_subtract_height = header_label_height - visible_header_label_height; m_ui->StaticHeaderLabel->setFixedHeight(static_header_height - header_subtract_height); } else { m_ui->StaticHeaderLabel->setFixedHeight(static_header_height); }
With this the static header label gets smaller but the header in the scroll area gets also smaller. This is probably due to resizing(scroll are gets more space).
I also trying moving the labels without success...
I don't really know how to tackle this problem. I am doing it wrong alltogether? Is there a more convenient way to achieve this?
Thanks in advance.