Shinmera / qtools

Qtools is a collection of utilities to aid development with CommonQt
https://shinmera.github.io/qtools
zlib License
210 stars 17 forks source link

How would you load an image and display it? #38

Closed jsalzbergedu closed 5 years ago

jsalzbergedu commented 5 years ago

I've tried:

(named-readtables:in-readtable :qtools)

(define-widget main (QWidget)
  ())

(define-subwidget (main label)
    (let ((label (q+:make-qlabel))
          (pixmap (q+:make-qpixmap)))
      (q+:load pixmap ...)
      (print (format t "pixmap is null? ~A" (q+:is-null pixmap)))
      (q+:set-pixmap label pixmap)
      label))

(defun app-main ()
  (with-main-window (window (make-instance 'main))))

Then ran app-main, found out that the pixmap is not null, yet saw nothing but an empty pane. So how would you load an image and display it?

Thanks.

phoe commented 5 years ago

The subwidget is not added to the layout of main and therefore it is not drawn. Simply defining a subwidget does not make it visible or added to any layouts; you must do it manually.

A roughly done and untested example:

(define-subwidget (main layout) (q+:make-qvboxlayout main))

(define-subwidget (main label)
  ...
  (q+:add-widget layout label))
jsalzbergedu commented 5 years ago

Lol thank you I suspected that I was just being unintelligent

phoe commented 5 years ago

Not really unintelligent, I would say - if you're only learning the framework and Qt right now, then it's obvious that you'll need some help now and then.