# Another Qt question

**URL:** <https://www.ruby-forum.com/t/another-qt-question/170234>\
**Category:** Ruby\
**Created:** [June 14, 2009, 6:01pm UTC](https://www.ruby-forum.com/t/another-qt-question/170234 "2009-06-14T18:01:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ther](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/977dab/32.png) [@ther](https://www.ruby-forum.com/u/ther)\
**Post date:** [June 14, 2009, 6:01pm UTC](https://www.ruby-forum.com/t/another-qt-question/170234/1 "2009-06-14T18:01:54Z")

</div>

def create\_central\_widget  
cw = Qt::Widget.new self  
self.central\_widget = cw

# Input search text

```
@search_text = Qt::LineEdit.new
@search_text.text = 'Search?'

```

# Search result list

```
@search_result = Qt::ListWidget.new

```

# Dummy fill

```
1.upto(100) { |i| @search_result.add_item i.to_s }

```

# Middle window is editor

```
@big_editor = Qt::TextEdit.new
@big_editor.setPlainText("Just a text")

search_area_widget = Qt::Widget.new

l = Qt::VBoxLayout.new search_area_widget cw
l.add_widget @search_text
l.add_widget @search_result

splitter = Qt::Splitter.new cw
splitter.add_widget(search_area_widget)
splitter.add_widget(@big_editor)

```

end  
##########################################################

This is part of program which creates main window dialog.

I would like to have two areas splitted by splitter. On the left side  
there a two widgets. Input search LineEdit widget and search result  
ListWidget widget. They both reside on VBoxLayout.

On the second area there is big\_editor TextEdit widget.

My problem is that I expect that dialog will fill whole dialog window.  
It will be streched from to to bottom and from left to right. But it  
doesnt. It has it’s default size (which I was unuble to resize). I have  
tried all kind of streches but nothing helps.

Splitter works as expected. It resizes left and right part of split area  
and widget resize ok.

What am I doing wrong.

by  
TheR

---

<div class="post-metadata">

**Author:** ![ther](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/977dab/32.png) [@ther](https://www.ruby-forum.com/u/ther)\
**Post date:** [June 14, 2009, 7:47pm UTC](https://www.ruby-forum.com/t/another-qt-question/170234/2 "2009-06-14T19:47:33Z")

</div>

On Sunday 14 June 2009, Damjan R. wrote:

> |# Middle window is editor  
> | splitter.add\_widget(search\_area\_widget)  
> |  
> |What am I doing wrong.  
> You aren’t adding a layout to your central widget. As a rule, every time  
> you  
> create a container widget (that is, a widget which contains other  
> widgets),  
> you have to give it a layout. If you do, the widget will take care of  
> managing  
> the size of child widgets; if you don’t you’ll find that child widgets  
> won’t  
> fill it or, worse, will extend outside its borders. In your case, you’re  
> only  
> adding a single widget to the layout, so you could use either a  
> Qt::VBoxLayout  
> or Qt::HBoxLayout. To do so, simply add the following two lines before  
> the end  
> of the method:

cw.layout = Qt::VBoxLayout.new cw  
cw.add\_widget splitter

However, I think you use cw only to contain the layout. In this case, it  
would  
be much more simple to use the splitter itself as central widget. Doing  
so,  
your code would become something like this:

def create\_central\_widget  
splitter = Qt::Splitter.new self  
self.central\_widget = splitter  
# Input search text  
@search\_text = Qt::LineEdit.new  
@search\_text.text = ‘Search?’  
# Search result list  
@search\_result = Qt::ListWidget.new  
# Dummy fill  
1.upto(100) { |i| @search\_result.add\_item i.to\_s }  
# Middle window is editor  
@big\_editor = Qt::TextEdit.new  
@big\_editor.setPlainText(“Just a text”)

```
search_area_widget = Qt::Widget.new splitter

l = Qt::VBoxLayout.new search_area_widget
l.add_widget @search_text
l.add_widget @search_result

splitter.add_widget(search_area_widget)
splitter.add_widget(@big_editor)

```

end

Note that there’s a mistake in your original code. The line

l = Qt::VBoxLayout.new search\_area\_widget cw

should become

l = Qt::VBoxLayout.new search\_area\_widget

At any rate, usually one doesn’t build container widgets by hand, but  
uses the  
Qt Designer to visually create them.

I hope this helps

Stefano

---

<div class="post-metadata">

**Author:** ![ther](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/977dab/32.png) [@ther](https://www.ruby-forum.com/u/ther)\
**Post date:** [June 14, 2009, 8:26pm UTC](https://www.ruby-forum.com/t/another-qt-question/170234/3 "2009-06-14T20:26:24Z")

</div>

Yep. Thank you. It helped.

I thought that I should learn first coding GUI by hand, so I would  
understand the way things work. I was using Rails for last years and my  
GUI experiance wasn’t any good before.

And this is simple enough example, so Qt Designer is an overkill.

by  
TheR
