Ok, now the removing of QLayouts works. Unfortunatly I can't add new QLayouts to the QGridLayout at runtime. If I want to add them in the constructor of my QMainWindow it's no problem. But adding them later does not work properly. So the QGridLayout receives the new Layout but does not display it.
I read the Qt-list archive, where someone suggested to call activate on the QGridLayout, but this does not work - not a surprise as this suggestion is from 1998...
Any ideas?
EDIT: update() does not change anything
Last edited by grosem; 2nd January 2007 at 09:15.
It should work. Did you, by any chance, forget to show() the widgets added at runtime?
J-P Nurmi
I do the same as I did in the constructor of QMainWindow (where the Items are shown). If I did not have to call show() there explicitly I don't have to do it somewhere else, have I?
The Items I add are looking like that
QHBoxLayout->QFrame->QLabel and QLabel;
If I call show on QFrame it opens seperatly new windows. show() at the QLabels has no effect.
Child widgets (which are not explicitly hidden) become visible too when their ancestor is shown. So you don't have to explicitly call show() for child widgets created in window constructor or so, as you will call show() for the window later anyway. But later at runtime when the window is already visible, adding more child widgets requires also an explicit show() to be called on the children.
Sounds like a parenting issue. A widget with no parent is same as a top level window. So the QFrame has no parent. And the QLabel won't be visible if it's parent (QFrame) is hidden.
Double check the code where you do the reparenting/layout switching. There must be a quirk somewhere.
J-P Nurmi
EDIT: Maybe I found the problem
EDIT2: Indeed I did. Ok, I did not, but it works now. As you said I had to call show() to the single widgets.
There was a small mistake: I did it this way
QHBoxLayout->QFrame->QHBoxLayout->QLabel and QLabel;
The additional QFrame is for easy layouting and dragndrop.
So I add the QFrame to the QHBoxLayout. Is not the QHBoxLayout now automatically the new parent? Because of your suggestion I tried
Qt Code:
addWidget(itemframe) //it's in the constructor of the derived QHBoxLayout class itemframe->setParent(this) //this is the QHBoxLayoutTo copy to clipboard, switch view to plain text mode
but the compiler says that only a QWidget can be the parent of itemframe :-/
btw.: jpn, you're my personal hero for this month![]()
Last edited by grosem; 2nd January 2007 at 10:29.
Glad to hear it finally works.
By the way, the usual approach to manage child widgets is to subclass some widget and do the handling there. It is quite unusual to subclass a layout for handling children, at least if no changes to the actual layout handling is made.
J-P Nurmi
Bookmarks