#include <qpe/qpeapplication.h> // 使用するクラスを指定する #include "mainwindow.h" // 使用するプログラムを指定する int main(int argc, char *argv[]) { QPEApplication a(argc,argv); Mainwindow *mw = new Mainwindow(); a.showMainWidget(mw); return a.exec(); }
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <qmainwindow.h> // 使用するクラスを指定する #include <qapplication.h> #include <qpushbutton.h> #include <qtextcodec.h> #include <qfont.h> #include <qmenubar.h> class Mainwindow : public QWidget{ Q_OBJECT public: Mainwindow(QWidget *parent = 0, const char *name = 0); private: QTextCodec *codec; // テキストコーデック QPushButton *button; // ボタン QMenuBar *menubar; // メニューバー private slots: // スロットを使うことで自分で機能を作れます void slot_button_text_change(); // slot_button_text_change() という「ボタンのテキストを変更する」ためのスロットを作成する }; #endif //MAINWINDOW_H
#include "mainwindow.h" // mainwindow.cpp のヘッダーファイル mainwindow.h を読み込み Mainwindow::Mainwindow(QWidget *parent, const char *name) : QWidget(parent, name) { // テキストコーデック「codec」を作成 // 以降、codec->toUnicode("ここに書いたことは日本語で表示できる") codec = QTextCodec::codecForName("ShiftJIS"); // ウィンドウのタイトルを設定 setCaption(codec->toUnicode("サンプル2「メニューバーを作成する」")); // 使用するフォントを設定 QFont f("lcfont",18); setFont(f); // ボタン「button」を作成(「Quit」と表示されたボタン) button = new QPushButton(codec->toUnicode("Quit"), this); // ボタン「button」の配置位置を指定 setGeometry(配置x座標,配置y座標,ボタンの横幅,ボタンの縦幅) button -> setGeometry(200, 80, 70, 25); // メニューバーを画面上に配置 menubar = new QMenuBar( this ); QPopupMenu *m_customize = new QPopupMenu(this); // メニュー項目「m_customize」を作成 m_customize->insertItem( codec->toUnicode("ボタンの文字をかえる"), this, SLOT(slot_button_text_change()) ); //項目「ボタンの文字をかえる」が選択されたら「this(=?)」に対して「slot_button_text_change()(=後で設定)」を実行させる QPopupMenu *m_menu = new QPopupMenu(this); // メニュー項目「m_menu」を作成 m_menu->insertItem( codec->toUnicode("終了する"), qApp, SLOT(quit()) ); //項目「終了する」が選択されたら「qApp(=アプリケーション)」に対して「quit()(=終了)」を実行させる // メニューバー「menubar」に項目を追加する。ここで追加した順に左から表示される。 menubar->insertItem( codec->toUnicode("メニュー"), m_menu ); // メニューバー「menubar」に「m_menu」を「メニュー」という表示で追加 menubar->insertItem( codec->toUnicode("カスタマイズ"), m_customize ); // メニューバーに「m_customize」を「カスタマイズ」という表示で追加 menubar->setSeparator( QMenuBar::InWindowsStyle ); // ウィンドウズみたいなスタイル // 「button」が「clicked()(=押した)」されたら「qApp(=アプリケーション)」に対して「quit()(=終了)」を実行させる QObject::connect( button, SIGNAL(clicked()), qApp, SLOT(quit()) ); } // スロット「slot_button_text_change()」を作成 void Mainwindow::slot_button_text_change() { button -> setText(codec->toUnicode("終了する")); // ボタン「button」の表示を「終了する」に設定する }
. ~/SLZaurus/bin/dev-arm-qpe.sh cd ~/SLZaurus/sample0002 progen -o sample0002.pro tmake -o Makefile sample0002.pro make |
前へ ○○○ 「リナザウのソフトウェア開発」 ○○○ 次へ