QAction QAction close Action close Action new Qaction

  • Slides: 18
Download presentation

QActionクラス • 初期化例 QAction *close. Action ; //ヘッダファイル close. Action = new Qaction(“閉じる”, this);

QActionクラス • 初期化例 QAction *close. Action ; //ヘッダファイル close. Action = new Qaction(“閉じる”, this); //ソースファイル(thisはMain. Windowインスタンス) • スロット接続例 connect( close. Action, SIGNAL( triggered() ), this, SLOT( close() ) );

ウィンドウを閉じる時の処理 • ユーザに問いかけを行うok. To. Continue関数の実装 bool Main. Window: : ok. To. Continue() { if(is.

ウィンドウを閉じる時の処理 • ユーザに問いかけを行うok. To. Continue関数の実装 bool Main. Window: : ok. To. Continue() { if(is. Window. Modified()) { //ウィンドウの”変更有り”のフラグを見る int ret = QMessage. Box: : warning(this, tr("Text. Editor"), "テキストは変更されています。n変更を保存しますか?", QMessage. Box: : Yes | QMessage. Box: : Default, QMessage. Box: : No, QMessage. Box: : Cancel | QMessage. Box: : Escape); if(ret == QMessage. Box: : Yes) return save(); //ファイル保存処理 else if(ret == QMessage. Box: : Cancel) return false; } return true; } • Yes:ファイルの保存、No:保存せずに閉じる、Cancel:保存せずウィンドウを閉じな い