QT中实现页面滚动下页面后有些字不能完全显示(最顶条目录,和最低层目录),怎么调试对齐
void InformationList::roll_to_current_page()
{
float average_value;
float upper_limit_value;
float lower_limit_value;
float current_offset;
float distance_value;
InformationListItem *p_first_item = (InformationListItem *)(contentsLayout->itemAt(0));
InformationListItem *p_last_item = (InformationListItem *)(contentsLayout->itemAt(contentsLayout->count()-1));
InformationListItem *p_four_item = (InformationListItem *)(contentsLayout->itemAt(3));
InformationListItem *p_current_item = (InformationListItem *)(contentsLayout->itemAt(m_old_index));
average_value = ((p_last_item->y()) - (p_first_item->y())) / (contentsLayout->count()-1);
upper_limit_value = p_first_item->y();
lower_limit_value = p_four_item->y();
if (m_old_index >= 0 && m_old_index <= 3)
{
current_offset = m_pScroll->offset();
m_pScroll->setOffset(current_offset - (contentsLayout->count())*average_value);
}
else if (m_old_index >= (contentsLayout->count() - 4) && m_old_index <= (contentsLayout->count() - 1))
{
current_offset = m_pScroll->offset();
m_pScroll->setOffset(current_offset + (contentsLayout->count())*average_value);
}
else
{
current_offset = m_pScroll->offset();
if ((p_current_item->y() - current_offset) > lower_limit_value)
{
m_pScroll->setOffset(current_offset + (p_current_item->y() - current_offset - lower_limit_value) + average_value*3);
}
if ((p_current_item->y() - current_offset) < upper_limit_value)
{
m_pScroll->setOffset(current_offset - ((-1)*(p_current_item->y() - current_offset - upper_limit_value)));
}
}
}