hakeの日記

Windows環境でプログラミングの勉強をしています。

メッセージの表示

Ruby/Qteの勉強 その19

QMessageBoxクラスを使用することでメッセージ用のウィンドウをポップアップさせることができる。メッセージの種類は、.information、.warning、.critical等のメソッドで選択可能。selfより後の引数は、キャプション、本文、ボタン0〓のラベル名となる。
メッセージウィンドウが表示されている間は、呼び出した側のプログラムは停止していて、ボタンまたは×をタップすることでウィンドウが閉じ実行が再開される。戻り値は、左のボタンから0,1,2、×の場合は-1になる。

#!/usr/bin/env ruby

require "qte"
require "qpe"
include Qte
include Qpe


class SampleWindow < QMainWindow
   def initialize()
      super()
      setCaption(tr("サンプル"))
      @msg = QLabel.new(tr("これはサンプルプログラム"),self)
      @msg.setGeometry(10,10,300,30)


      @ebox1 = QMultiLineEdit.new(self)
      @ebox1.setGeometry(0,280,635,120)
      @ebox1.setReadOnly(true)

      @pb1 = QPushButton.new(tr("ボタン1"),self)
      @pb1.setGeometry(320,5,100,30)
      connect(@pb1,QSIGNAL("clicked()"), self, 'openMsg')

   end

   def openMsg
      @ebox1.clear
      @ebox1.insertLine("Open Message Window")

#      i = QMessageBox.information(self, "caption", "const")
      i = QMessageBox.information(self, "caption", "const", "btn0", "btn1", "btn2")
#      i = QMessageBox.warning(self, "caption", "const", "btn0", "btn1", "btn2")
#      i = QMessageBox.critical(self, "caption", "const", "btn0", "btn1", "btn2")
#      i = QMessageBox.about(self, "caption", "const")
#      i = QMessageBox.aboutQt(self, "caption")

      @ebox1.insertLine("ret=" + i.to_s)
      @ebox1.insertLine("Close Message Window")
   end

end

$defaultCodec = QTextCodec.codecForName("utf8")
app = QPEApplication.new([$0]+ARGV)
app.setDefaultCodec($defaultCodec)
QApplication.setFont(QFont.new("lcfont",18))
app.showMainWidget(SampleWindow.new)
app.exec