PDA

View Full Version : Why QStatusBar do not at the bottom?



FinderCheng
28th September 2009, 16:05
I put a QStatusBar in a QMdiSubWindow. Then I added a QGraphicsView and this QStatusBar into a QVBoxLayout and wanted to get a subwindow just like the QMainWindow. But when I did this, I found that if I resized the subwindow draging mouse the QStatusBar would not at the bottom of QMdiSubWindow.(The red bar is the QStatusBar.) I don't know why. Can anyone help me? Thank you all!

http://image215.poco.cn/mypoco/myphoto/20090928/21/53514647200909282140492738953539508_000.jpg

caduel
28th September 2009, 16:54
show us some code, so we don't have to guess...

from looking at your screenshot:
check the margins of your layout.

FinderCheng
29th September 2009, 02:51
I put a QStatusBar in a QMdiSubWindow. Then I added a QGraphicsView and this QStatusBar into a QVBoxLayout and wanted to get a subwindow just like the QMainWindow. But when I did this, I found that if I resized the subwindow draging mouse the QStatusBar would not at the bottom of QMdiSubWindow.(The red bar is the QStatusBar.) I don't know why. Can anyone help me? Thank you all!

http://image215.poco.cn/mypoco/myphoto/20090928/21/53514647200909282140492738953539508_000.jpg

Yeah, here are some related code.



// projectwindowpanel.cpp
// code in main panel with a view which extends QGraphcisView and a status bar
// sizeHint() of this view has be overrideed in order to show the full image
view = new ProjectView(project, this);
QSize viewSize = view->sizeHint();
view->setGeometry(0, 0, viewSize.width(), viewSize.width());

statusBar = new QStatusBar(this);
statusBar->setGeometry(0, viewSize.height(), viewSize.width(), 15);
statusBar->setStyleSheet(QString("background-color: red"));

QVBoxLayout *vbox = new QVBoxLayout;
vbox->setMargin(0);
vbox->setSpacing(0);
vbox->addWidget(view, 0, Qt::AlignHCenter);
vbox->addWidget(statusBar);
setLayout(vbox);

// override sizeHint() in projectwindowpanel.cpp
QSize GPF::ProjectWindowPanel::sizeHint() const
{
return QSize(view->sizeHint().width(), view->sizeHint().height() + 15);
}

//======================
// projectwindow.cpp
// project window extends QMdiSubWindow with a minimum size
// and set project window panel as its centre widget
setMinimumSize(200, 200);

mainPanel = new ProjectWindowPanel(project, this);
setWidget(mainPanel);


PS: I have removed the sizeHint() in projectwindowpanel.cpp, the problem is still there.

caduel
29th September 2009, 08:38
calling setGeometry when using QLayout is of no use.

I'd try:
* remove the setGeometry() calls
* remove the sizeHint() implementation
* remove the setMinimumSize() call - when everything works, try setting the minimum size on the graphicsview

Lykurg
29th September 2009, 09:16
did you notice QMainWindow::setStatusBar()?

FinderCheng
29th September 2009, 09:26
did you notice QMainWindow::setStatusBar()?

Yeah, but I put this QStatusBar in a subclass of QMdiSubWindow not QMainWindow.

By the way, I have set the ProjectView, the main panel which is white, to be fixed size. When I remove this code, it is just fine. But I need it to be fixed. Then I added qDebug in resizeEvent of ProjectWindowPanel and found that the size did not change when I resize the subwindow. I think it is because the main panel of it is fixed size...