(ql:quickload '(lorem-ipsum qtools qtcore qtgui qtsvg)) (named-readtables:in-readtable :qtools) (in-package #:cl+qt) ;;; FIXED-QTEXTEDIT (define-widget fixed-qtextedit (qtextedit) ()) (define-subwidget (fixed-qtextedit fix-context-menu-widget) (q+:make-qwidget)) (define-override (fixed-qtextedit context-menu-event) (event) ;; Display the context menu. (with-finalizing ((menu (q+:create-standard-context-menu fixed-qtextedit))) (q+:exec menu (q+:global-pos event))) ;; Work around the bug. (q+:show fix-context-menu-widget) (setf (q+:focus fix-context-menu-widget) 0) (q+:hide fix-context-menu-widget) ;; Fix cursor position after the context menu disappears. (let* ((position (q+:pos event)) (cursor (q+:cursor-for-position fixed-qtextedit position))) (setf (q+:text-cursor fixed-qtextedit) cursor))) (defun test () (with-main-window (editor 'my-editor) (dotimes (i 5) (q+:append editor (lorem-ipsum:paragraph :prologue nil))) (let ((document (q+:document editor)) (pathnames (directory *pathname*))) (dolist (pathname pathnames) (let ((svg-path (uiop:native-namestring pathname))) (with-finalizing ((icon (q+:make-qicon svg-path))) (let ((pixmap (q+:pixmap icon (q+:make-qsize))) (format (q+:make-qtextimageformat)) (url (uiop:strcat "gateway://" (pathname-name pathname)))) (q+:add-resource document (q+:qtextdocument.image-resource) (q+:make-qurl url) (q+:to-image pixmap)) (setf (q+:name format) url) (q+:append editor (format nil "