Qt-interest Archive, March 2008
Size problem about setCentralWidget
Message 1 in thread
Hi,all
I create a mainwindow and resize it:
resize(QApplication::desktop()->size());
// and the mainwindow's width and height is 1280x800 , and it is maximumed
//then I create a QVBox and a QListView
QVbox *c=new QVbox(this);
// and create QListViews in c
setCentralWidget(c);
// here I print the width and heigth of c, I got c_width=100, c_height=30;
// but the screen display shows that c is about 1270*770
// and two listviews in c displays well about 1270*380,1270*380
//here's a refresh function to refresh listview
//the listview displays local system's directory content
void MyClass::reloadDirectoryContent()
{
//here I print the width and height of c again,
//then I got the right width 1275x750
}
So, when my program started, the centralWidght displays as 1270x770, but
the really size is 100,30
then, I refresh the QListView ( through reloadDirectoryConten())
then the centrolWidgth prints the size as 1275x775
Why it has a size(100,30) ,but displays 1270x770, and after a reload
it changes to size(1275x775) ?
Thanks.
--
[ signature omitted ]
Message 2 in thread
On 30.03.08 15:50:00, jefix wrote:
> resize(QApplication::desktop()->size());
> // and the mainwindow's width and height is 1280x800 , and it is maximumed
> //then I create a QVBox and a QListView
> QVbox *c=new QVbox(this);
> // and create QListViews in c
> setCentralWidget(c);
> // here I print the width and heigth of c, I got c_width=100, c_height=30;
> // but the screen display shows that c is about 1270*770
> // and two listviews in c displays well about 1270*380,1270*380
Thats no proper way of debugging (well actually it is, but not in this
case).
> Why it has a size(100,30) ,but displays 1270x770, and after a reload
> it changes to size(1275x775) ?
You're missing a piece here. When you print that size out, the widget
really is 100x30. However the mainwindow is not shown at that point, so
you can't see that size, its only shown after you call show() and start
the event loop via exec(). The event loop then processes the show event
and also the resize events and resizes the window to the proper size and
then shows it. If you want to see how that happens install an event
filter on your mainwindow and check for the resize event.
Andreas
--
[ signature omitted ]
Message 3 in thread
I see.
Then how to resize some widget in init ( before exec() ) ?
Take the last example,
In MyClass::MyClass I have this:
dirListView->setColumnWidth(0, c->width()*40/100);
// as you point , this cannot display well, and it does,because c->width()=100
So, after exec(), then I click reload button to call
MyClass::reloadDirectoryContent()
then dirListView->setColumnWidth(0,c->width()*40/100) in
reloadDirectoryContent() function displays column(0) well ,because
c->width() is
the right width now.
Then, how to displays dirListView's 0 column well in MyClass:MyClass (
before exec() ) ?
Thanks.
2008/3/30, Andreas Pakulat <apaku@xxxxxx>:
> On 30.03.08 15:50:00, jefix wrote:
> > resize(QApplication::desktop()->size());
> > // and the mainwindow's width and height is 1280x800 , and it is maximumed
> > //then I create a QVBox and a QListView
> > QVbox *c=new QVbox(this);
> > // and create QListViews in c
> > setCentralWidget(c);
> > // here I print the width and heigth of c, I got c_width=100, c_height=30;
> > // but the screen display shows that c is about 1270*770
> > // and two listviews in c displays well about 1270*380,1270*380
>
>
> Thats no proper way of debugging (well actually it is, but not in this
> case).
>
>
> > Why it has a size(100,30) ,but displays 1270x770, and after a reload
> > it changes to size(1275x775) ?
>
>
> You're missing a piece here. When you print that size out, the widget
> really is 100x30. However the mainwindow is not shown at that point, so
> you can't see that size, its only shown after you call show() and start
> the event loop via exec(). The event loop then processes the show event
> and also the resize events and resizes the window to the proper size and
> then shows it. If you want to see how that happens install an event
> filter on your mainwindow and check for the resize event.
>
> Andreas
>
> --
> It was all so different before everything changed.
>
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
--
[ signature omitted ]
Message 4 in thread
On 30.03.08 17:57:16, jefix wrote:
> I see.
> Then how to resize some widget in init ( before exec() ) ?
> Take the last example,
> In MyClass::MyClass I have this:
>
> dirListView->setColumnWidth(0, c->width()*40/100);
> // as you point , this cannot display well, and it does,because c->width()=100
>
> So, after exec(), then I click reload button to call
> MyClass::reloadDirectoryContent()
>
> then dirListView->setColumnWidth(0,c->width()*40/100) in
> reloadDirectoryContent() function displays column(0) well ,because
> c->width() is
> the right width now.
>
> Then, how to displays dirListView's 0 column well in MyClass:MyClass (
> before exec() ) ?
By getting notified when the window is resized, either using an
eventFilter or overridign the resizeEvent() function from QWidget.
Andreas
--
[ signature omitted ]
Message 5 in thread
Hi,again
I tried eventFilter, and the listview's column 0 did displays well.
But some other problems, it cannot maximum show in QVbox c , some gray area
leaves, here's my code:
seems not enough, but I dont know how to complete,
Thanks.
dirListView->installEventFilter(this);
bool MyClass::eventFilter(QObject *obj,QEvent *e)
{
if( obj==dirListView && e->type() == QEvent::Resize )
{
dirListView->setColumnWidth(0, c->width()*40/100)
return true;
}
else
return false;
}
2008/3/30, Andreas Pakulat <apaku@xxxxxx>:
> On 30.03.08 17:57:16, jefix wrote:
> > I see.
> > Then how to resize some widget in init ( before exec() ) ?
> > Take the last example,
> > In MyClass::MyClass I have this:
> >
> > dirListView->setColumnWidth(0, c->width()*40/100);
> > // as you point , this cannot display well, and it does,because c->width()=100
> >
> > So, after exec(), then I click reload button to call
> > MyClass::reloadDirectoryContent()
> >
> > then dirListView->setColumnWidth(0,c->width()*40/100) in
> > reloadDirectoryContent() function displays column(0) well ,because
> > c->width() is
> > the right width now.
> >
> > Then, how to displays dirListView's 0 column well in MyClass:MyClass (
> > before exec() ) ?
>
>
> By getting notified when the window is resized, either using an
> eventFilter or overridign the resizeEvent() function from QWidget.
>
> Andreas
>
>
> --
> Your talents will be recognized and suitably rewarded.
>
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
--
[ signature omitted ]
Message 6 in thread
On 30.03.08 19:12:01, jefix wrote:
> Hi,again
>
> I tried eventFilter, and the listview's column 0 did displays well.
> But some other problems, it cannot maximum show in QVbox c , some gray area
> leaves, here's my code:
> seems not enough, but I dont know how to complete,
You need to provide a complete, but small example that reproduces the
problem so people can follow your description.
From your description it sounds as if either you've got an empty qwidget
somewhere or a spacer or you're missing a layout at some place. But
without the complete code thats impossible to say for sure.
Andreas
--
[ signature omitted ]