I have a class DetailsView derived from QScrollArea. The class member iDescBox which is of type QGroupBox contains QTextBrowser iDescription item within it.
I wolud like to adjust height of iDescBox according to content of iDescription because I don't want to have vertical scrollbar in iDescBox.
I have created method adjustDescription which is called from showEvent and resizeEvent of DetailsView, unfortunately it does not do what I wanted it to do.
When I enter(make visible) DetailsView for the first time I can see vertical scrollbar in iDescBox. When I enter DetailsView second time iDescBox is adjusted correctly and when I enter DetailsView for the third time it has a horizontal scrollbar. After this secuence repeats
Can anybody tell me what am I doing wrong, I attach source of adjustDescription method ?
void DetailsView::adjustDescription()
{
if (iDescBox->isVisible())
{
QMargins margs = iDescBox->contentsMargins();
int w = viewport()->width()
- margs.left() - margs.right();
doc->setTextWidth(w);
doc->adjustSize();
int h = doc->size().toSize().height()
+ margs.bottom() + margs.top() + 27;
//If adjusted document size is bigger then viewport size and vertical
//scrollbar is not displayed then adjust description one more time
if ( iDescBox->y() + h > viewport()->height()
&& !verticalScrollBar()->isVisible())
{
w -= verticalScrollBar()->width();
doc->setTextWidth(w);
doc->adjustSize();
h = doc->size().toSize().height()
+ margs.bottom() + margs.top() + 27;
}
iDescBox->setMinimumHeight(h);
iDescBox->setMaximumHeight(h);
}
}
void DetailsView::adjustDescription()
{
if (iDescBox->isVisible())
{
QMargins margs = iDescBox->contentsMargins();
int w = viewport()->width()
- margs.left() - margs.right();
QTextDocument* doc = iDescription->document();
doc->setTextWidth(w);
doc->adjustSize();
int h = doc->size().toSize().height()
+ margs.bottom() + margs.top() + 27;
//If adjusted document size is bigger then viewport size and vertical
//scrollbar is not displayed then adjust description one more time
if ( iDescBox->y() + h > viewport()->height()
&& !verticalScrollBar()->isVisible())
{
w -= verticalScrollBar()->width();
doc->setTextWidth(w);
doc->adjustSize();
h = doc->size().toSize().height()
+ margs.bottom() + margs.top() + 27;
}
iDescBox->setMinimumHeight(h);
iDescBox->setMaximumHeight(h);
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks