Results 1 to 6 of 6

Thread: add Widgets in widgets

  1. #1

    Default add Widgets in widgets

    Hi,
    my problem is to insert some widgets in one "main" widget (not MainWindow!).
    I built a widget by using Qt designer (e.g. widget1) and created a class (widget2) to implement some functions for widget1.
    In the next step I created a new widget (widget3) which has only a tableWidget inside.

    My Problem is, if I create another widget (widget4) in which I want to place those two widgets (wiget2, widget3) there is nothing to see in widget4.

    Here is my code of widget4:
    Qt Code:
    1. require 'Qt4'
    2. require 'Widget2'
    3. require 'Widget3'
    4.  
    5. class Widget4 < Qt::Widget
    6. def initialize()
    7. super()
    8.  
    9. @layout = Qt::VBoxLayout.new()
    10.  
    11. @widget2 = Widget2.new
    12. @widget3 = Widget3.new
    13. @layout.addWidget(@widget2)
    14. @layout.addWidget(@widget3)
    15.  
    16. setLayout(@layout)
    17. size = Qt::Size.new(500, 500)
    18. size = size.expandedTo(minimumSizeHint())
    19. resize(size)
    20. end
    21. end
    To copy to clipboard, switch view to plain text mode 

    Hope u can help me,

    THX
    WingMan
    Last edited by jacek; 31st August 2008 at 16:41. Reason: changed [qtclass] to [code]

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: add Widgets in widgets

    How are you adding widget4 ??
    if u want widget2 and widget3, u need to set them in layout... something ilke -

    Qt Code:
    1. lay4->addWidget(widget2);
    2. lay4->addWidget(widget3);
    3. widget4->setLayout(widget4);
    4.  
    5. layout->addWidget(widget4);
    6. setLayout(layout);
    To copy to clipboard, switch view to plain text mode 

  3. #3

    Default Re: add Widgets in widgets

    My fault, forgot to mention: Programming in ruby not in C++!
    I add those two Widgets in a layout by
    Qt Code:
    1. @layout.addWidget(@widget2)
    2. @layout.addWidget(@widget3)
    To copy to clipboard, switch view to plain text mode 

    And widget4 is the widget which has to display the layout with widget2 and 3 so I thoght I don't need to add it into the layout???

    WingMan

  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: add Widgets in widgets

    Your code looks OK. What happens if you replace widget2 and widget3 with QPushButtons?

  5. #5

    Default Re: add Widgets in widgets

    The problem seems to be widget2. Without widget2 everything looks fine!
    How can I add a widget (widget2) which inherits from a widget which is created by Designer(widget1)?
    my way:
    widget 2:
    Qt Code:
    1. @a = Ui::XYZ.new() #new instance of widget1
    2. @a.setupUi(self)
    To copy to clipboard, switch view to plain text mode 
    and add widget2 in widget 4
    Qt Code:
    1. @widget2 = Widget2.new(self)
    2. @layout.addWidget(@widget2)
    To copy to clipboard, switch view to plain text mode 

    But there is nothing to see.
    Without the layout, widget2 is shown in wdget4, but... without layout-management!

    bye,
    WingMan

  6. #6

    Default Re: add Widgets in widgets

    solved

    wrong layout-management in designer-widget

    THX a lot!!!

Similar Threads

  1. Qt3 - Multiple transparent widgets
    By bythesea in forum Qt Programming
    Replies: 4
    Last Post: 11th September 2009, 11:24
  2. Replies: 2
    Last Post: 16th May 2008, 14:39
  3. widgets behind hidden widgets not working
    By bpetty in forum Newbie
    Replies: 13
    Last Post: 7th September 2007, 20:23
  4. Performance in hiding/showing widgets
    By Paalrammer in forum Newbie
    Replies: 12
    Last Post: 14th February 2007, 18:57
  5. Creating Widgets
    By hylke in forum Qt Programming
    Replies: 2
    Last Post: 5th February 2006, 08:37

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
  •  
Qt is a trademark of The Qt Company.