PDA

View Full Version : add Widgets in widgets



WingMan
31st August 2008, 08:50
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:


require 'Qt4'
require 'Widget2'
require 'Widget3'

class Widget4 < Qt::Widget
def initialize()
super()

@layout = Qt::VBoxLayout.new()

@widget2 = Widget2.new
@widget3 = Widget3.new
@layout.addWidget(@widget2)
@layout.addWidget(@widget3)

setLayout(@layout)
size = Qt::Size.new(500, 500)
size = size.expandedTo(minimumSizeHint())
resize(size)
end
end

Hope u can help me,

THX
WingMan

aamer4yu
31st August 2008, 17:32
How are you adding widget4 ??
if u want widget2 and widget3, u need to set them in layout... something ilke -


QHBoxLayout *lay4 = new QHBoxLayout;
lay4->addWidget(widget2);
lay4->addWidget(widget3);
widget4->setLayout(widget4);

layout->addWidget(widget4);
setLayout(layout);

WingMan
31st August 2008, 19:28
My fault, forgot to mention: Programming in ruby not in C++!
I add those two Widgets in a layout by

@layout.addWidget(@widget2)
@layout.addWidget(@widget3)

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

jacek
1st September 2008, 00:48
Your code looks OK. What happens if you replace widget2 and widget3 with QPushButtons?

WingMan
1st September 2008, 05:49
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:


@a = Ui::XYZ.new() #new instance of widget1
@a.setupUi(self)

and add widget2 in widget 4


@widget2 = Widget2.new(self)
@layout.addWidget(@widget2)


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

bye,
WingMan

WingMan
1st September 2008, 07:23
solved :p

wrong layout-management in designer-widget :o

THX a lot!!!