Qt4 widget and nested layout issue.
Hey all,
I've got a problem with a nested layout.
First off I'm creating the main widget items.
Then I'm passsing it to my first view to create its Qt components :
Code:
ZeLoginView
::ZeLoginView(QWidget *parent, ZeClientController
& clientController
) :
At the end of the process I'm deleting this view and free the layout of my main widget :
Code:
void ZeGlobalController::SetView(ViewMode viewMode)
{
delete this->layout(); [...]
}
Finally I'm passing my main widget to another view with a "Nested layout" :
Code:
ZeUserView
::ZeUserView(QWidget *parent, ZeUserController
& userController
) : {
ZeLog::Get()->AddLine("--- Creating the user view ---\n");
// User Infos
// User picture
mUserPictureLabel
= new QLabel;
mUserPictureLabel
->setPixmap
(QPixmap("zeData/profil_no_pic.jpg"));
mUserInfoLayout->addWidget(mUserPictureLabel, 1, 1, Qt::AlignCenter);
// Login label
mLoginLabel->setText(tr("Login"));
mUserInfoLayout->addWidget(mLoginLabel, 2, 1, Qt::AlignCenter);
// Message combo box
mMessageComboBox->setFixedWidth(100);
mUserInfoLayout->addWidget(mMessageComboBox, 3, 1, Qt::AlignCenter);
// Status combo box
mStatusComboBox->setEditable(true);
mStatusComboBox->setFixedWidth(100);
mUserInfoLayout->addWidget(mStatusComboBox, 4, 1, Qt::AlignCenter);
// Layout stretch
mUserInfoLayout->setColumnStretch(0, 10);
mUserInfoLayout->setColumnStretch(2, 10);
mUserLayout->addLayout(mUserInfoLayout);
}
For some reason the nested layout : mUserInfoLayout, never appears : blank window.
And even more strange, it's working in two cases:
1. If I don't use nested layout to show my components.
2. Working with nested stuff If I'm creating the second view at first.
Looks like something is messed up between the first view and the second creation.
There must be something wrong with the main widget, is there anything I could have forgot beside the delete layout() ?
In advance thanks.
Ben.
Re: Qt4 widget and nested layout issue.
What is the base class of ZeUserController?
Re: Qt4 widget and nested layout issue.
Quote:
Originally Posted by
bunjee
There must be something wrong with the main widget, is there anything I could have forgot beside the delete layout() ?
Why do you delete that layout and where do you call QWidget::setLayout()?
Re: Qt4 widget and nested layout issue.
Here is the base class of the ZeUserController.
Code:
class ZeUserController
: public QWidget{
Q_OBJECT
I have one Widget for the main window of the application and many views.
As I read in Qt doc, a Widget cannot have several layouts,
I'm deleting the previous one in order to assign my next view.
Code:
void ZeGlobalController::SetView(ViewMode viewMode)
{
ClearControllers();
delete this->layout();
switch (viewMode)
{
case LOGIN_VIEW:
mClientController = new ZeClientController(*(ZeClient::Get()));
mClientController->GenerateView();
break;
case CONTACT_VIEW:
mUserController = new ZeUserController();
mUserController->GenerateView();
default:
break;
}
}
Re: Qt4 widget and nested layout issue.
Quote:
Originally Posted by
bunjee
I'm deleting the previous one in order to assign my next view.
OK and where do you call setLayout()?
Re: Qt4 widget and nested layout issue.
Code:
ZeLoginView
::ZeLoginView(QWidget *parent, ZeClientController
& clientController
) : {
// Login layout
In the constructor of mLoginLayout in ZeLoginView.
Code:
ZeUserView
::ZeUserView(QWidget *parent, ZeUserController
& userController
) : {
In the constructor of mUserLayout in ZeUserView.
Re: Qt4 widget and nested layout issue.
That's an awful way to do that (tightly couples the two widgets). Why not reuse the layout instead of creating a new one?
Re: Qt4 widget and nested layout issue.
In one case I need a QGrid in another a QHBox as main layout.
Re: Qt4 widget and nested layout issue.
But in both cases they can be children of the parent widget's layout. Your "view" should be a complete widget (having its own layout), not a complete layout. Then you can simply add the widget to the parent's layout.
Re: Qt4 widget and nested layout issue.
Quote:
Originally Posted by
bunjee
mLoginLayout = new QGridLayout(parent);
...
mUserLayout = new QVBoxLayout(parent);
I see, but in this case you end with a widget that has no layout and no child widgets.
Re: Qt4 widget and nested layout issue.
Thanks a lot guys,
I've changed my approach :
" One widget has one layout and sticks with it ".
Even though I don't understand why this option:
... doesn't work.
Re: Qt4 widget and nested layout issue.
Quote:
Originally Posted by
bunjee
Even though I don't understand why this option: [...]
... doesn't work.
Maybe you don't see any other widgets because they are hidden under those empty ZexxxView widgets?
Re: Qt4 widget and nested layout issue.
Or you just didn't call show() on them...