[Kde-bindings] QT TextEdit refresh
Carl Bourne
cbourne at intellect.co.uk
Tue Jul 24 17:09:06 UTC 2007
Richard,
Thanks for the prompt reply - that did the trick.
Just need to try and find a good place where this sort of stuff is documented!
I've seen the pragmatic Ruby QT book, but that's QT 3 based a seems a bit on the light side.
Can you recommend anything publications that's QT/Ruby specific? Don't fancy trying to learn C++.
Best Regards,
Carl
________________________________
From: Richard Dale [mailto:rdale at foton.es]
Sent: Tue 24/07/2007 17:48
To: KDE bindings for other programming languages
Subject: Re: [Kde-bindings] QT TextEdit refresh
On Tuesday 24 July 2007, Carl Bourne wrote:
> 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()
The Qt::TextEdit won't get repainted until you return to the event loop. So if
you do everything inside to go() method you won't return to the event loop
until you've done the 50 iterations.
You need to do the 'Generating files' processing in another method, that is
called once before control returns to the event loop like this for instance:
class MyWidget < Qt::Widget
slots :go, :generate
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.font = Qt::Font.new('Arial', 12, Qt::Font::Bold)
connect(quit, SIGNAL(:clicked)) {@textedit.clear(); go() }
end
def go
# @textedit.clear()
@textedit.text = "Generating files:-"
@count = 0
generate
end
def generate
@count += 1
@textedit.append("Generating file: "+ at count.to_s)
puts "hello"
if @count == 50
@textedit.append("Done")
else
@timer = Qt::Timer.singleShot(100, self, SLOT(:generate))
end
end
end
PS: The two pieces of your code didn't seem to quite match as there was no
Dialog class in dialog.rb..
-- Richard
_______________________________________________
Kde-bindings mailing list
Kde-bindings at kde.org
https://mail.kde.org/mailman/listinfo/kde-bindings
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.476 / Virus Database: 269.10.16/914 - Release Date: 23/07/2007 19:45
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-bindings/attachments/20070724/407ad830/attachment.html>
More information about the Kde-bindings
mailing list