Displaying QML Item over a QWidget - qt

I want to make an application that will benefit both from OpenGL and QML advantages. I want to use QOpenGLWidget and place QML Item over it. Item will be partially transparent. I though it may be possible by using QQuickView but I just figured out that it does cover all transparent parts with black color. An attempt to achieve what I need (an example project) may be found on my GitHub here.
Is it possible to render QML Item with all children onto an existing QWidget in such way that it is visible under Item, wherever Item is not completely opaque?
I guess that in the worst case scenario I could create bitmaps from the QWidget and the Item objects, somehow combine and display them but I seek easier way. If there is no easier way I could just never display those two at the same time.
The reason why I do not want to use OpenGL features in QML directly is this. Maybe I should just use the work around mentioned in the link.

I think you don't need Widgets for it. You can do custom rendering in QtQuick using QQuickFramebufferObject class. I used to do it before, though don't have code anymore. This article seems to explain what to do https://blog.qt.io/blog/2015/05/11/integrating-custom-opengl-rendering-with-qt-quick-via-qquickframebufferobject/

Related

How can I add custom graphics in Qt designer?

I'm comfortable with C++ but brand new to Qt. I apologize for my ignorance as I'm sure this is a very simple question. I'd like to make a custom clickable widget, basically a push button that is just a black square with Qt designer, but don't have any idea on where to start.
EDIT: after fumbling around I think I'm an epsilon closer.
I created a black_box.png file. In the resource browser I created a new resource and prefix, and added the black_box.png. Any advice from here?
You have a few options for what you want to achieve.
You can use custom painting to draw a new button that subclasses QPushButton, this is reasonably involved and provides a huge amount of flexibility to build it to your requirements.
You can use Qt's stylesheets mechanism to style it, you can get more information on it here: http://doc.qt.io/qt-5/stylesheet.html
Or you can set a QPixmap of your image to be a button icon, and size your button to match it, there's a good answer on how to do this on this question: How to set image on QPushButton?

Zooming a view in PyQt?

I have a simple to do tree application that displays a QTreeView inside of a QMainWindow. I want to give the user the ability to change the magnification level of the content (using a spinbox most likely), but without actually changing the underlying font size of the text.
Is there a way to do this without changing my whole app to a QGraphicsScene? The app is just showing a good-old fashioned tree with text, no graphics or anything fancy other than wanting to change the magnification of the view; hence, I am thinking that switching to a graphics scene would be overkill.
Or, am I wrong, and switching to a graphics scene is the only simple way to do it?
Note a trimmed down version of the app is at Code Review. It contains a SSCCE, but is a bit long to post here.
In a site discussing how to put widgets on a scene, trolltech wrote (emphasis added):
I myself and several other Trolls’ve spent some time researching this
topic [how to embed a widget in a QGraphicsScene]. It’s not trivial;
most solutions to embedding widgets into a scene end up with several
serious drawbacks. That’s also why Qt doesn’t have any off-the-shelf
solution to this.
Widgets cannot be scaled or rotated, but graphics items can.
This suggests I cannot perform, in a simple way, the operations I want to on my QWidget by itself. That is, perhaps I need to add it to a scene, which is what I was trying to avoid. If that is the answer, then I'll accept it and start a new question if I get stuck doing that.
Note I just found this question, which is pretty much a duplicate, and does not have an (accepted) answer.
Related content
http://www.qtcentre.org/threads/62745-Zoom-a-view
QTableView Zoom In/Out
Drawing widgets (such as buttons) over QGraphicsView
QGraphicsView Zooming in and out under mouse position using mouse wheel
https://forum.qt.io/topic/15308/qgraphicsview-zooming-with-qslider
https://wiki.qt.io/Smooth_Zoom_In_QGraphicsView
As suggested by the docs quoted from trolltech in the original question, there is no built-in method to zoom on a view.
If the goal is to avoid the use of QGraphicsViews, the simplest way to separate the size of the font on the screen, versus the size of the font saved or printed, is to basically have two fonts. One to be displayed on the screen you can call 'zoom', versus the other to be saved/printed and call that 'font size'.
I got this idea from qtcentre (in a post I added to the original post too):
http://www.qtcentre.org/threads/62745-Zoom-a-view

Play a video with custom overlay graphics

I want to play a video (with sound) in a simple GUI with "play" and "stop" buttons etc. There are classes and widgets in Qt's Phonon module for doing that, and several examples. OK, so that seems to be simple.
But now I need to draw some custom graphics (that depend on the current time in the video) on top of the streamed video image. I have not found anything about this in the Qt documentation. What's the canonical way of doing this? Do I just create a custom VideoWidget widget and override its paintEvent? In another question here, some guy seemed to have trouble with this.
Any pointers would be appreciated.
Use QGraphicsView and QGraphicsWidgets. You can put your Phonon::VideoWidget inside a QGraphicsProxyWidget and it becomes usable as a QGraphicsWidget.
For custom overlays, inherit QGraphicsWidget and override the paint function to draw your custom widgets. You can add them to your scene and they will appear on top of your video widget.
Your solution cannot work because you cannot add a QGLWidget to QGraphicsProxyWidget. Please look at
http://doc.qt.digia.com/qt/qgraphicsproxywidget.html
Note that widgets with the Qt::WA_PaintOnScreen widget attribute set
and widgets that wrap an external application or controller cannot be
embedded. Examples are QGLWidget and QAxWidget.
Please correct me if I'm wrong.

Classes to use for a flexible image selection/tagging widget in Qt

I'm new with Qt and am looking for advice on how to structure this.
I want a flexible widget that can display a set of images (normally read from a directory but other sources too) and let the user select images with the arrow keys and/or mouse and also apply custom tags.
For example there might be 5 tags defined by the application. A user can press a key to select one, and then a little icon would appear in or near the image preview showing that it was selected for that tag.
Would I need to implement this from scratch via drawing on a QWidget or is there something that would make a sensible base class? Thanks!
I would use a QListView base class, and then subclass QStyledItemDelegate.
There is an example here which might help you.

Can A Sprite Contain A MovieClip?

Hmmm... I'm working at creating an AS3 UI library, since most of the ones out there each seem to miss out at least 1 feature I need. In order to keep it lightweight, I created everything from scratch. I use Sprites to render just about anything. But I want to allow the user of the library the possibility of adding a custom graphic for a button. Now... maybe that graphic is a MovieClip which has a nice animation within it.
So can I say sprite.addChild(mc) and then if I do mc.play, will the mc play within a sprite?
Thank you ::- ).
Yes.
Sprite extends DisplayObjectContainer which can contain any DisplayObject or subclass of DisplayObject.

Resources