[prev in list] [next in list] [prev in thread] [next in thread]
List: ruby-talk
Subject: Re: rubyQT
From: "Rob Kaufman" <rgkaufman () gmail ! com>
Date: 2007-07-24 17:02:45
Message-ID: 17112e2f0707241002m273d3838u1703d68194d8d7c5 () mail ! gmail ! com
[Download RAW message or body]
Hi Carl,
Assuming that the problem your having is that you type and not text
shows up, I was not able to reproduce the issue. I did have to make
the following changes to get your code to run at all:
------
my_widget.rb
-------
class MyWidget < Qt::Widget
slots 'go()'
def initialize(parent = nil)
super(parent)
setFixedSize(500, 500)
@textedit = Qt::TextEdit.new(self)
@textedit.setGeometry(5, 50, 480, 300)
quit = Qt::PushButton.new(('Generate'), self)
quit.setGeometry(5, 5, 100, 30)
quit.setFont(Qt::Font.new('Arial', 12, Qt::Font::Bold))
connect(quit, SIGNAL(:clicked)) {@textedit.clear(); go() }
end
def go
# @textedit.clear()
@textedit.setText("Generating files:-")
count = 0
50.times do
count+=1
sleep 0.1
@textedit.append("Generating file: "+count.to_s)
puts "hello"
end
@textedit.append("Done")
end
end
if $0 == __FILE__
a = Qt::Application.new(ARGV)
w = MyWidget.new
a.mainWidget = w # **IMPORTANT ADDITION**
w.show
a.exec
end
You'll notice that I'm only using one file (my_widget.rb) instead of
the two file structure you had before. The main.rb would work like
this:
------
main.rb
-------
require 'my_widget'
a = Qt::Application.new(ARGV)
w = MyWidget.new
a.mainWidget = w
w.show
a.exec
'exec'ing in multiple places, instantiating more than one instance of
Qt::Application and not adding the main widget to the application
instance are all issues I saw in your code that are fixed in the
above.
Hope That Helps,
Rob Kaufman
On 7/24/07, Carl Bourne <carl.bourne@intellect.co.uk> wrote:
> Hi,
>
> I wonder if you can help. I'm currently exploring rubyqt in conjunction
> with the latest QT4 libraries. However, I can't seem to get a TextEdit
> widget to refresh properly. My code runs correctly when I click the
> button that has a ruby function assigned to it, but the TextEdit field
> does not update until the ruby function completes.
>
> Here's the code I'm using:-
>
>
> --------------------------------------------------------------------------------------------------
> main.rb
> ----------
> require 'Qt'
> require 'dialog.rb'
> app = Qt::Application.new(ARGV)
> dialog = Dialog.new
> dialog.exec
>
> ------
> dialog.rb
> -------
>
> class MyWidget < Qt::Widget
> slots 'go()'
> def initialize(parent = nil)
> super(parent)
> setFixedSize(500, 500)
> @textedit = Qt::TextEdit.new(self)
> @textedit.setGeometry(5, 50, 480, 300)
>
> quit = Qt::PushButton.new(('Generate'), self)
> quit.setGeometry(5, 5, 100, 30)
> quit.setFont(Qt::Font.new('Arial', 12, Qt::Font::Bold))
> connect(quit, SIGNAL(:clicked)) {@textedit.clear(); go() }
> end
>
> def go
> # @textedit.clear()
> @textedit.setText("Generating files:-")
> count = 0
> 50.times do
> count+=1
> sleep 0.1
> @textedit.append("Generating file: "+count.to_s)
> puts "hello"
> end
> @textedit.append("Done")
> end
> end
> app = Qt::Application.new(ARGV)
> widget = MyWidget.new()
> widget.show()
> app.exec()
>
> -------------------------------------------------------------------------------------------------
> --
> Posted via http://www.ruby-forum.com/.
>
>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic