1 Attachment(s)
resizing widget inside QScrollArea
I have a QScrollArea, and I want the widget inside its viewPort to be resized to the maximum viewport size.
I have my class Dialog derived from QDialog and I have redefined resizeEvent() method, as follows:
Code:
#include <QVBoxLayout>
{
sa->setMinimumSize(400,300);
sa->setVerticalScrollBarPolicy ( Qt::ScrollBarAlwaysOn );
sa->setHorizontalScrollBarPolicy ( Qt::ScrollBarAlwaysOn );
sa->setWidget(qd);
mainLayout->addWidget(sa);
setLayout(mainLayout);
}
Dialog::~Dialog()
{
delete qd;
delete sa;
delete layout();
}
#include <cstdio>
{
qd->resize(sa->viewport()->contentsRect().size());
str
= "sa->viewport()->contentsRect().size() " + QString::number(sa
->viewport
()->contentsRect
().
size().
width()) + "," + QString::number(sa
->viewport
()->contentsRect
().
size().
height());
printf("%s\n", str.toAscii().constData());
}
Once started I expect the QDial to be resized to viewPort size, but I obtain the following:
http://img32.imageshack.us/img32/947...scrollarea.png
And on the console it is wrote:
Quote:
sa->viewport()->contentsRect().size() 96,26
as if the QScrollArea was something like 100x30. But if I try to resize all works, so the piece of code in resizeEvent() works.
What is wrong? Where is the mistake?
I also attach the project
thanks
Re: resizing widget inside QScrollArea
u are not helping the qdial to resize are u ?
qd->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
Re: resizing widget inside QScrollArea
Quote:
Originally Posted by
manishkyl
u are not helping the qdial to resize are u ?
qd->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
and u are not tring to resize the dialog manually aren't u?
Even if the sizePolicy is Fixed I can resize the qdial, infact resizing the dialog manually all works.
Instead when the application start, the first time the widgets are shown, the qdial is too small, and it seems that is the QScrollArea::viewPort to be very small.
Please try to compile and take a look at the console.
If you simply start and close the application without other interaction, you can see on the console
Quote:
sa->viewport()->contentsRect().size() 96,26
then try to start and resize the dialog. What is written on console?
It seems that the first time I read sa->viewport()->contentsRect().size() the scrollarea is not yet resized to its final size
thanks
Re: resizing widget inside QScrollArea
Re: resizing widget inside QScrollArea
Quote:
Originally Posted by
jpn
I don't know... the widget need to be resized so as a magnification only horizontally.
thanks