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))))
メニューバーも出してみましたが、自分の環境だとショートカットがうまく動かなくいです。
0 件のコメント:
コメントを投稿