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.
|# 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:
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”)
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.