Results 1 to 4 of 4

Thread: Access an QHBoxLayout, which name you don't know

  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Access an QHBoxLayout, which name you don't know

    Hi,

    inside a class I have:
    Qt Code:
    1. QGroupBox *gb = new QGroupBox(search_easy);
    2. QHBoxLayout* hboxLayout = new QHBoxLayout(gb);
    To copy to clipboard, switch view to plain text mode 
    And now I want to chance the direction of the QGroupBox, without using hboxLayout!

    There is an gb->layout(), but that only return a QLayout, not my hboxLayout, which I need. Is it possible to recive a pointer to the QHBoxLayout hboxLayout, if one does not know its name (in my example 'hboxLayout')?

    Thanks

    Lykurg

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Access an QHBoxLayout, which name you don't know

    layout() returns the widget's layout. You have to cast it to another class if you want to have QHBoxLayout instead of QLayout. qobject_cast and/or QMetaObject::className() might come in handy here to know the layout class.

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Access an QHBoxLayout, which name you don't know

    Qt Code:
    1. qobject_cast<QHBoxLayout *>(gb->layout())->setDirection( QBoxLayout::TopToBottom );
    To copy to clipboard, switch view to plain text mode 

    works fine.

    Thanks a lot, Lykurg.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Access an QHBoxLayout, which name you don't know

    Something like this would be better:
    Qt Code:
    1. QHBoxLayout *l = qobject_cast<QHBoxLayout *>(gb->layout());
    2. if(l) l->setDirection( QBoxLayout::TopToBottom );
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Error in connecting to MS ACCESS
    By cutie.monkey in forum Qt Programming
    Replies: 0
    Last Post: 9th September 2008, 02:10
  2. class QHBoxLayout
    By csvivek in forum Installation and Deployment
    Replies: 2
    Last Post: 10th April 2008, 07:57
  3. Help with alignment
    By IsleWitch in forum Newbie
    Replies: 1
    Last Post: 20th October 2007, 18:20
  4. Access Violation on Signal Emit
    By khagzan in forum Qt Programming
    Replies: 2
    Last Post: 25th September 2007, 22:51
  5. QHBoxLayout Problem
    By Seema Rao in forum Qt Programming
    Replies: 5
    Last Post: 29th April 2006, 15:51

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.