This is my workaround:
void listTab::changeTo(QString& it)
{
bool funkysb;
int min;
int max;
int range;
int row;
int r;
int c = ui.listWidget->count();
int v;
sb = ui.listWidget->verticalScrollBar();
min = sb->minimum();
max = sb->maximum();
range = max - min;
funkysb = ((range == 0) && (c != 0));
if (funkysb)
{
// The scrollbar range is zero and the control contains
// items, set the scroll range to something useful
min = 0;
max = c - 1;
range = max - min;
sb->setRange(min, max);
}
// Find the specified number in the list
for (row = 0; row < c; row++)
{
number = ui.listWidget->item(row)->text();
if (number == it)
{
// Make it the current selection
// This resets the scrollbar range to 0,0 if the
// list is in a tab widget with a layout
ui.listWidget->setCurrentRow(row);
ui.listWidget->item(row)->setSelected(true);
// Reset the scrollbar range if we have funkiness
r = sb->maximum() - sb->minimum();
if (funkysb && (r != range))
{
sb->setRange(min, max);
// Scroll to the item
sb = ui.listWidget->verticalScrollBar();
r = (row + 1) * range;
c = ui.listWidget->count();
v = r / c;
if (r % c)
{
v++;
}
sb->setValue(v);
}
break;
}
}
}
void listTab::changeTo(QString& it)
{
bool funkysb;
int min;
int max;
int range;
int row;
int r;
int c = ui.listWidget->count();
int v;
QString number;
QScrollBar* sb;
sb = ui.listWidget->verticalScrollBar();
min = sb->minimum();
max = sb->maximum();
range = max - min;
funkysb = ((range == 0) && (c != 0));
if (funkysb)
{
// The scrollbar range is zero and the control contains
// items, set the scroll range to something useful
min = 0;
max = c - 1;
range = max - min;
sb->setRange(min, max);
}
// Find the specified number in the list
for (row = 0; row < c; row++)
{
number = ui.listWidget->item(row)->text();
if (number == it)
{
// Make it the current selection
// This resets the scrollbar range to 0,0 if the
// list is in a tab widget with a layout
ui.listWidget->setCurrentRow(row);
ui.listWidget->item(row)->setSelected(true);
// Reset the scrollbar range if we have funkiness
r = sb->maximum() - sb->minimum();
if (funkysb && (r != range))
{
sb->setRange(min, max);
// Scroll to the item
sb = ui.listWidget->verticalScrollBar();
r = (row + 1) * range;
c = ui.listWidget->count();
v = r / c;
if (r % c)
{
v++;
}
sb->setValue(v);
}
break;
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks