Python + Qt4からRuby + Qt4への移植例の継続
パート2
次に、次の質問について考えてみましょう。ファイルが選択されていない場合、またはテキストに変更が加えられていない場合、「保存」ボタンは無効にする必要があります。
Qt Disignerの「enabled」プロパティはアクティビティを担当します。または、このプロパティは、setEnabledメソッドを使用してルビーコードから設定できます。
b_saveボタンを設定してfalseプロパティを有効にし(ボックスをオフにします)、editor.rbフォームを再生成します。
テキストが変更されたことを確認するには、textEditにtextChanged()シグナルを使用します。
start.rbコードを次のように変更しましょう。
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
Copy Source | Copy HTML require 'Qt4' require 'editor.rb' class StartQT4 < Qt::MainWindow slots 'file_dialog()' , 'file_save()' , 'enable_save()' def initialize parent= nil super @ui = Ui_Notepad.new @ui.setupUi self Qt:: Object .connect(@ui.b_open, SIGNAL( 'clicked()' ), self , SLOT( 'file_dialog()' )) Qt:: Object .connect(@ui.b_save, SIGNAL( 'clicked()' ), self , SLOT( 'file_save()' )) Qt:: Object .connect(@ui.editor_window, SIGNAL( 'textChanged()' ), self , SLOT( 'enable_save()' )) end def file_dialog f = Qt::FileDialog if @filename = f.getOpenFileName text = File . new (@filename).read @ui.editor_window.setText text # # "" textChanged() @ui.b_save.setEnabled false end end def enable_save @ui.b_save.setEnabled true end def file_save if @filename f = File .new @filename, 'w' f. puts @ui.editor_window.toPlainText f.close end end end if $ 0 == __FILE__ app = Qt::Application. new (ARGV) myapp = StartQT4 .new myapp.show app. exec end
追加されたもの。 textEditでテキストが変更され、ボタンをアクティブにするときに呼び出されるスロットを追加しました。
Copy Source | Copy HTML
- Qt :: Object .connect(@ ui.editor_window、SIGNAL( 'textChanged()' )、 self 、SLOT( 'enable_save()' ))
Copy Source | Copy HTML
- def enable_save
- @ ui.b_save.setEnabled true
- 終わり
file_dialogメソッドで、ファイルからtextEditにテキストを追加すると、ボタンが非アクティブになります。
Copy Source | Copy HTML
- @ ui.b_save.setEnabled false
ファイルを開くと、現在開いているファイルの変更は保存されません。 ダイアログボックス(メッセージボックス)を作成する必要があります。このダイアログボックスでは、「保存」、「保存しない」、「キャンセル」などの変更について尋ねられます。 これらの目的のために、MessageBoxを使用します。
メッセージボックス呼び出しは次のとおりです。
Copy Source | Copy HTML
- メッセージ= Qt :: MessageBox.new
- メッセージ。 幹部
このウィンドウを設定する必要があります。 ボタンとテキストを追加します。 しかし、これをどのように行うのでしょうか? file_dialogメソッドを編集し、変更が行われた場合はメッセージを表示する必要があります。 変更があったかどうかはどのようにしてわかりますか? 「保存」ボタンがアクティブな場合(@ ui.b_save.idEnabled)-未保存の変更があります。 そして、変更を行います。
Copy Source | Copy HTML
- 「Qt4」が 必要
- 「editor.rb」が 必要
- クラス StartQT4 <Qt :: MainWindow
- スロット'file_dialog()' 、 'file_save()' 、 'enable_save()'
- def 初期化親= nil
- スーパー
- @ui = Ui_Notepad.new
- @ ui.setupUi self
- Qt :: Object .connect(@ ui.b_open、SIGNAL( ' clicked ()' )、 self 、SLOT( 'file_dialog()' ))
- Qt :: Object .connect(@ ui.b_save、SIGNAL( ' clicked ()' )、 self 、SLOT( 'file_save()' ))
- Qt :: Object .connect(@ ui.editor_window、SIGNAL( 'textChanged()' )、 self 、SLOT( 'enable_save()' ))
- 終わり
- def file_dialog
- 応答= false
- #ボタンテキスト:
- save = 'Save'
- discard = 「保存しない」
- キャンセル= 'キャンセル'
- #変更があった場合、message_boxを呼び出す
- if @ ui.b_save.isEnabled && @filename
- メッセージ= Qt :: MessageBox.new
- message.setText 「未保存の変更で何をすべきか?」
- message.setWindowTitle( 'メモ帳' )
- message.setIcon(Qt :: MessageBox.Question)
- message.addButton(保存、Qt :: MessageBox.AcceptRole)
- message.addButton(破棄、Qt :: MessageBox.DestructiveRole)
- message.addButton(キャンセル、Qt :: MessageBox.RejectRole)
- message.setDetailedText( 「保存されていないファイルの変更:」 + @ filename.to_s)
- メッセージ。 幹部
- 応答= message.clickedButton.text
- #ファイルを保存する
- 応答==保存の場合
- file_save
- @ ui.b_save.setEnabled false
- 終わり
- #保存しない
- 応答==破棄の場合
- @ ui.b_save.setEnabled false
- 終わり
- 終わり
- #変更を保存したくない場合
- 応答==キャンセルしない限り
- f = Qt :: FileDialog
- if @filename = f.getOpenFileName
- text = File 。 new (@filename).read
- @ ui.editor_window.setTextテキスト
- @ ui.b_save.setEnabled false
- 終わり
- 終わり
- 終わり
- def enable_save
- @ ui.b_save.setEnabled true
- 終わり
- def file_save
- @filenameの場合
- f = File .new @filename、 'w'
- f。 puts @ ui.editor_window.toPlainText
- f.close
- 終わり
- 終わり
- 終わり
- $ 0 == __FILE__の 場合
- app = Qt ::アプリケーション。 新規 (ARGV)
- myapp = StartQT4 .new
- myapp.show
- アプリ。 幹部
- 終わり
行18〜46に加えられた変更
Qt :: MessageBoxクラスの新しいインスタンスを作成し、メッセージテキスト(setText)、ウィンドウタイトルをsetWindowTitle、アイコン(setIcon)に割り当て、3つのボタンを設定します(「保存」、「保存しない」、「キャンセル」)。 2番目の引数として、ボタンのタイプ(ロール)を設定します。 これらのタイプに関する情報は、QTドキュメントに記載されています。 setDetailedTextは、「詳細の表示」ボタンをクリックしたときの詳細なメッセージ出力を設定します。 そして最後に、execメソッドを呼び出します。 message.clickedButton-押されたボタンのpushButtonタイプを返します。 この例では、このボタンのテキストを使用して操作します。
ダイアログボックスは次のようになります。
サンプルのソースコードは、次の場所からダウンロードできます。
前の例: narod.ru/disk/6746280000/ruby_qt_simple_editor_1.zip.html
現在の例: narod.ru/disk/6746302000/ruby_qt_simple_editor_2.zip.html
次の例のルビーへの移植: www.rkblog.rk.edu.pl/w/p/extending-pyqt4-text-editor