ラベル CommonQt の投稿を表示しています。 すべての投稿を表示
ラベル CommonQt の投稿を表示しています。 すべての投稿を表示

2011年2月9日水曜日

CommonQtでコンテキストメニュー

CommonQtでコンテキストメニュー(右クリック時に出てくるメニュー)を出してみます。

(asdf:load-system :qt)
(defpackage :test
(:use :cl :qt)
(:export main))

(in-package :test)

(enable-syntax)

(defvar *qapp*)

(defclass test-window ()
((quit-action :accessor quit-action-of :initform nil)
(file-menu :accessor file-menu-of :initform nil))
(:metaclass qt-class)
(:qt-superclass "QMainWindow")
(:override
("contextMenuEvent" context-menu-event)))

(defmethod initialize-instance :after ((instance test-window) &key parent)
(if parent
(new instance parent)
(new instance))
(setf (quit-action-of instance)
(#_new QAction "&Quit" instance))
(#_setShortcut (quit-action-of instance)
(#_new QKeySequence (#_CTRL "Qt") (#_Key_Q "Qt")))

(#_connect "QObject"
(quit-action-of instance) (QSIGNAL "triggered()")
instance (QSLOT "close()"))
(let ((menu-bar (#_menuBar instance)))
(setf (file-menu-of instance)
(#_addMenu menu-bar "&File"))
(#_addAction (file-menu-of instance)
(quit-action-of instance))))



(defmethod context-menu-event ((instance test-window) event)
(let ((menu (#_new QMenu instance)))
(#_addAction menu (quit-action-of instance))
(#_exec menu (#_globalPos event))))

(defun main ()
(setf *qapp* (make-qapplication))
(let ((window (make-instance 'test-window)))
(#_setGeometry window 300 100 300 200)
(#_show window)
(unwind-protect
(#_exec *qapp*)
(#_hide window))))

メニューバーも出してみましたが、自分の環境だとショートカットがうまく動かなくいです。

CommonLisp, Qt, CommonQt

2011年1月19日水曜日

CommonQtでHello world!

Common LispのQtバインディングであるCommonQtを触ってみました。 QtならマルチプラットフォームなのでどこでもGUIが使えます(たぶん)

Qtのチュートリアルにある以下のようなC++のコードは

// C++
#include <QApplication>
#include <QPushButton>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QPushButton hello("Hello world!");
hello.resize(100, 30);
hello.show();
return app.exec();
}

このように書けるようです。

;; Common Lisp (CommonQt)
(asdf:load-system "qt")

(defpackage :qt-user
(:use :qt :cl)
(:export main))

(in-package :qt-user)

(named-readtables:in-readtable :qt)

(defun main ()
(let ((app (qt:make-qapplication)))
;; QPushButton は 大文字小文字を区別する
(let ((hello (#_new QPushButton "Hello world!")))
(#_resize hello 100 30)
(#_show hello)
(#_exec app))))

(main)

ほとんどC++のコードをそのまま直しても動かせそうで良い感じです。