widget not visible after layout->setAlignment
The follow code shows the first widget added, (playerControlsToolbar, essentially a QToolBar) but not the TimeSlider widget (a custom widget with its own layout, a slider bar and a couple of labels as children).
If I comment out the 5th line, it does show up. (The same things happens if I add the TimeSlider using addWidget( pb, 0, Qt::AlignCenter) ).
Code:
playerAndSliderLayout->addWidget( playerControlsToolbar, 0, Qt::AlignCenter );
TimeSlider* pb = new TimeSlider( m_controlBar );
playerAndSliderLayout->addWidget( pb );
playerAndSliderLayout->setAlignment( pb, Qt::AlignCenter );
The layout does leave space for the "ghost" widget, it just doesn't show it.
Re: widget not visible after layout->setAlignment
When do you invoke the above code snippet? Have you tried creating TimeSlider without a parent?
Re: widget not visible after layout->setAlignment
When setting up a window. And yes I have tried it with a 0 parent.
Re: widget not visible after layout->setAlignment
Quote:
Originally Posted by
eean
When setting up a window.
So the window isn't visible yet, right?
What do you do with playerAndSliderLayout later?
Re: widget not visible after layout->setAlignment
Quote:
Originally Posted by
jacek
So the window isn't visible yet, right?
Well its in an init() function (not the constructor) so I'd assume its technically already visible.
Quote:
Originally Posted by
jacek
What do you do with playerAndSliderLayout later?
Nothing, it goes out of scope. Well, I set it as the layout for m_controlBar.
I actually redid the whole thing using Designer. Apparently designer doesn't let you set what the layout alignments are? So I did the following:
Code:
m_controlBar
= new QWidget( this );
Ui::ControlBar uicb;
uicb.setupUi( m_controlBar );
#define center( A, O ) uicb.A##boxLayout->setAlignment( uicb.O, Qt::AlignCenter )
center( v, m_progressBar );
center( v, m_playerControlsToolbar );
center( h, m_searchWidget );
center( h, m_analyzerWidget );
center( h, m_volumeWidget );
#undef center
Which compiles and I think does what its supposed to do.
...but everything but the m_playerControlsToolbar is invisible, just like before!
Re: widget not visible after layout->setAlignment
Quote:
Originally Posted by
eean
Well its in an init() function (not the constructor) so I'd assume its technically already visible.
If it's already visible, then you have to invoke pb->show() yourself.
Quote:
Originally Posted by
eean
...but everything but the m_playerControlsToolbar is invisible, just like before!
Have you placed m_controlBar inside some layout?
Re: widget not visible after layout->setAlignment
Quote:
Originally Posted by
jacek
If it's already visible, then you have to invoke pb->show() yourself.
Just tried that (added uicb.O->show() to the center macro above) and it has no effect. I don't see how this would be the issue since one widget is shown correctly.
Quote:
Originally Posted by
jacek
Have you placed m_controlBar inside some layout?
Its inserted into a splitter which is parented to the main window. So no, not really.
zchydem from #qt actually wrote a test program:
http://qtnode.net/pastebin/2554
And he says it all works correctly. :confused:
1 Attachment(s)
Re: widget not visible after layout->setAlignment
attached is an svn diff from Amarok 2.0, in case anyone has a KDE4 development environment laying around. ;)
Re: widget not visible after layout->setAlignment
Quote:
Originally Posted by
eean
Just tried that (added uicb.O->show() to the center macro above) and it has no effect. I don't see how this would be the issue since one widget is shown correctly.
Then maybe there is some problem with that custom widget?
Try something like this:
Code:
int main( int argc, char **argv )
{
TimeSlider w;
w.show();
return app.exec();
}
to check whether this TimeSlider behaves correctly.
Quote:
Originally Posted by
eean
Its inserted into a splitter which is parented to the main window. So no, not really.
But splitters behave like layouts, so it should be OK.
Re: widget not visible after layout->setAlignment
Another Amarok dev (Dan) tried to do this, but then realized that TimeSlider requires a bunch of other files to work.
Anyways, TimeSlider (and the other widgets with the same problem) did work as part of a grid layout previously. And of course, they work without their alignment set. :)
Re: widget not visible after layout->setAlignment
Quote:
Originally Posted by
eean
And of course, they work without their alignment set.
That's weird. Unfortunately I don't have KDE4 at hand, so I can't play with Amarok's code.