-
Hey everyone,
I was working on a separate Qt GUI project; and I realized Qt had no dedicated means of numeric plotting-- let alone for complex-valued plots. So I wrote some classes to support that; and stuck them in their own library:
https://git.sr.ht/~mehdyfaik/QGrip
The QComplexPlotView class is a widget you can drop right into your next form. Right away, it supports rubberband zoom; mousewheel zoom; and pan. Zooming scales the concrete graphics items behind the scenes; so lines are always the same perceived size regardless of zoom level. You can take a look at my QGripTest directory in the QGrip repository to see what an example client application can do with this widget.
Thanks for taking a look (:
-therealddx -
Hi, welcome to the forum and thanks for sharing.
I tried the example, but I don't think it works correctly. The plot is barely visible, no matter how much I zoom in and different points blink and are different size depending on the zoom level. There seems to be something wrong with item scaling and they end up sub-pixel size.
Also, a couple pointers for making a library:
- You've got a lot of code in headers. This kinda defeats the point of building a shared library, as all of that code gets compiled into the user's executable anyway. Move everything that is not a declaration, a public interface or a template to cpp files.
- You have a
QGRIP_EXPORT
define but you never mark anything with it. This means that when using compilers that don't export symbols by default (like MSVC on Windows) nothing is actually exported and no .lib file is created. This makes your library almost unusable as is. User either has to change it to be a static library (which might not be desirable) or modify a lot of the source to actually mark the needed classes for export. - It's always nice to include an example, but try to make it run out of the box. I had to fiddle with the .pro file and change some hardcoded paths to your build directory for it to compile properly.
- You've got a lot of debug messages in Debug config. You should put that behind a user configurable define. It's ok to have that as an option, but if user is debugging their own app they don't want the output window spammed with messages from your lib. Also make sure you put the QDebug include behind an ifdef. No need to increase dependencies in non-debug builds.
- I don't know if you know but you don't have to scale lines for them to keep width independent of zoom level. If you set QPen to cosmetic it does that automatically.
-
Thanks for your time and input. These are some important general engineering issues I didn't consider. I didn't know about the QPen cosmetic; is there a zoom-independent setting for QAbstractGraphicsShapeItem as well?
Yeah, the QComplexPlotView offers:
- Double-click -> fit to size
- Control-mousewheel -> zoom
- Shift-mousewheel -> pan left/right
If you run the test GUI again... try doing that double-click upon load. That's probably an oversight in how I wrote the test GUI.
-
@therealddx said:
is there a zoom-independent setting for QAbstractGraphicsShapeItem as well?
QAbstractGraphicsShapeItem has a setPen method, so you can give it a cosmetic pen.