Play a video with custom overlay graphics - qt

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.

Related

Displaying QML Item over a QWidget

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/

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?

Qt drawing with Qt designer

I have tried to search on the internet and here as well, without success though. I am using Qt 4.8.2 and design my app in the Designer, then I write code in VS2010. I would like to show a chart on the application window, e.g. like http://www.infocaptor.com/user_help/help_img/dashboard_line_chart_screen.png , based on some data that are created by the app.
In the Widget Box of the Designer, I can't find any widget related to drawing. So I tried creating a QTextEdit and drawing on that using QPainter. However, this does not work. I can draw on the whole appwindow, but not just on the text edit. So the question is: what widget can be added onto the app window in the designer and that is going to allow me to draw on it using QPainter?
I'm eluded as the documentation says specifically that QPainter can draw on any QWidget which a QTextEdit is...
Any help is much appreciated,
Daniel
The function of "drawing" is tooo complex/unspecific to be included as a specialized widget. You'll have to create it yourself and implement the desired drawing functions.
Here is an example which you can learn from, the scribblearea class could be pretty much what you are looking for. In that case you can copy it to your project and use in in the Qt-Designer by promoting a widget to this class.

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