PDA

View Full Version : widget not visible after layout->setAlignment



eean
24th March 2007, 17:47
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) ).


QVBoxLayout *playerAndSliderLayout = new QVBoxLayout;
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.

jacek
24th March 2007, 19:48
When do you invoke the above code snippet? Have you tried creating TimeSlider without a parent?

eean
24th March 2007, 20:26
When setting up a window. And yes I have tried it with a 0 parent.

jacek
24th March 2007, 20:35
When setting up a window.
So the window isn't visible yet, right?

What do you do with playerAndSliderLayout later?

eean
24th March 2007, 20:53
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.

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:


m_controlBar = new QWidget( this );
m_controlBar->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
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!

jacek
24th March 2007, 21:21
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.


...but everything but the m_playerControlsToolbar is invisible, just like before!
Have you placed m_controlBar inside some layout?

eean
24th March 2007, 21:57
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.


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:

eean
24th March 2007, 22:05
attached is an svn diff from Amarok 2.0, in case anyone has a KDE4 development environment laying around. ;)

jacek
24th March 2007, 22:53
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:

int main( int argc, char **argv )
{
QApplication app( argc, argv );

TimeSlider w;
w.show();

return app.exec();
}to check whether this TimeSlider behaves correctly.


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.

eean
26th March 2007, 03:24
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. :)

jacek
26th March 2007, 22:12
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.