Results 1 to 11 of 11

Thread: widget not visible after layout->setAlignment

  1. #1
    Join Date
    Mar 2007
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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) ).

    Qt Code:
    1. QVBoxLayout *playerAndSliderLayout = new QVBoxLayout;
    2. playerAndSliderLayout->addWidget( playerControlsToolbar, 0, Qt::AlignCenter );
    3. TimeSlider* pb = new TimeSlider( m_controlBar );
    4. playerAndSliderLayout->addWidget( pb );
    5. playerAndSliderLayout->setAlignment( pb, Qt::AlignCenter );
    To copy to clipboard, switch view to plain text mode 

    The layout does leave space for the "ghost" widget, it just doesn't show it.
    Last edited by eean; 24th March 2007 at 18:01.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: widget not visible after layout->setAlignment

    When do you invoke the above code snippet? Have you tried creating TimeSlider without a parent?

  3. #3
    Join Date
    Mar 2007
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: widget not visible after layout->setAlignment

    When setting up a window. And yes I have tried it with a 0 parent.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: widget not visible after layout->setAlignment

    Quote Originally Posted by eean View Post
    When setting up a window.
    So the window isn't visible yet, right?

    What do you do with playerAndSliderLayout later?

  5. #5
    Join Date
    Mar 2007
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: widget not visible after layout->setAlignment

    Quote Originally Posted by jacek View Post
    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 View Post
    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:
    Qt Code:
    1. m_controlBar = new QWidget( this );
    2. m_controlBar->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
    3. Ui::ControlBar uicb;
    4. uicb.setupUi( m_controlBar );
    5.  
    6. #define center( A, O ) uicb.A##boxLayout->setAlignment( uicb.O, Qt::AlignCenter )
    7. center( v, m_progressBar );
    8. center( v, m_playerControlsToolbar );
    9. center( h, m_searchWidget );
    10. center( h, m_analyzerWidget );
    11. center( h, m_volumeWidget );
    12. #undef center
    To copy to clipboard, switch view to plain text mode 

    Which compiles and I think does what its supposed to do.

    ...but everything but the m_playerControlsToolbar is invisible, just like before!

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: widget not visible after layout->setAlignment

    Quote Originally Posted by eean View Post
    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 View Post
    ...but everything but the m_playerControlsToolbar is invisible, just like before!
    Have you placed m_controlBar inside some layout?

  7. #7
    Join Date
    Mar 2007
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: widget not visible after layout->setAlignment

    Quote Originally Posted by jacek View Post
    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 View Post
    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.

  8. #8
    Join Date
    Mar 2007
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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.
    Attached Files Attached Files

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: widget not visible after layout->setAlignment

    Quote Originally Posted by eean View Post
    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:
    Qt Code:
    1. int main( int argc, char **argv )
    2. {
    3. QApplication app( argc, argv );
    4.  
    5. TimeSlider w;
    6. w.show();
    7.  
    8. return app.exec();
    9. }
    To copy to clipboard, switch view to plain text mode 
    to check whether this TimeSlider behaves correctly.

    Quote Originally Posted by eean View Post
    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.

  10. #10
    Join Date
    Mar 2007
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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.

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: widget not visible after layout->setAlignment

    Quote Originally Posted by eean View Post
    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.

Similar Threads

  1. changing layout of a widget
    By mikro in forum Qt Programming
    Replies: 10
    Last Post: 4th August 2009, 20:21
  2. Creating a square sized widget in a layout
    By cboles in forum Qt Programming
    Replies: 5
    Last Post: 22nd September 2008, 23:38
  3. Qt4 widget and nested layout issue.
    By bunjee in forum Qt Programming
    Replies: 12
    Last Post: 18th January 2007, 20:29
  4. How do I move a widget inside a grid Layout
    By barnabyr in forum Newbie
    Replies: 1
    Last Post: 8th May 2006, 23:23
  5. Replies: 4
    Last Post: 24th March 2006, 22:50

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.