Problem with QMainWindow +QGraphicsView and more than one QGLWidget - qt

I have a problem in my Qt Application. I have a QMainWindow with a QGraphicsScene and a QGLWidget as viewport.
The problem comes when I want to show another QGLWidget with other OpenGL information (for example, the general view and another window with the Top view).
In this case, the two windows don't work good and have problems with the transformation Matrix in OpenGL.
I try to use a shared widget (my first QGLWidget) and have the same context, but it fails anyway.
Any idea?
Thanks

This will be pretty difficult to without code. As a guess, perhaps you're not resetting your matrix operations to a known state before using them (see part 3 of the link)?

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/

Sudoku GUI using QTableView (QT5)

I'm trying to create a GUI for sudoku (for improving my QT5 skills). I have decided to use for these purposes a QTableView. Up until that point there is no problem.
Now i want to draw grids to make 3x3 fields more visible. Is there any ideas, how i can do that?
I would really recommend not using a QTableView for this, it's potentially solvable by using delegates (which are mostly for data presentation) but it would be very tricky. The best solution would be for you to build a custom widget by subclassing QWidget, building the paintEvent functionality and putting a data model in place. I know that building a custom widget certainly sounds more difficult, but it's actually quite simple.
Here's some good resources to get started with:
http://www.informit.com/articles/article.aspx?p=1405227
http://zetcode.com/gui/qt4/customwidget/
http://qt.developpez.com/doc/4.7/designer-customwidgetplugin/
http://qt.developpez.com/tutoriels/braindeadbzh/customwindow/
After that the QPainter class reference will be very useful to implement your drawing commands.

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.

Rendering SDL_surface on a QWidget in a platform-independent manner

I have a SDL_surface that plays a video in its own window. I want this window to be rendered on a QWidget. I want a generic solution because my targets are OSX, Windows and Linux.
I've come across 2 solutions summarized as below:
The Window ID hack involves setting SDL_WINDOWID to the QWidget's id so SDL pushes pixels on the QWidget. Here is an Example Qt snippet from a related thread.
However, this doesn't work on OS X and is not guaranteed to work on all Win and Linux platforms.
Manually copying from non-window SDL_surface to QWidget.
Found some example code for Gtk+ but nothing for Qt so far. The idea is to push the video to memory and pull it from QWidget. Surely one shouldn't use a QImage to render each frame. So how would one implement this copying?
There are possible duplicate questions but my question is more specific about platform-independence
Retrieve the pixels from the SDL_Surface and create a QImage with it, then use a QPainter to draw the QImage on the widget.

Base class in Qt Creator 4

I am new to Qt Creator 4. When I create a new project it gives me the option to choose a base class:
QWidget
QMainWindow
QDialog
I am confused which to choose. What difference does it make?
Does it also effect the code?
Kindly explain in simple words.
QDialog is specifically designed for dialog or "pop-up" windows. These are dialogs generated from your main application, useful for things like Open/Save dialogs or informational messages.
QMainWindow is a specific widget that has things like a menu bar, tool bar and status bar built-in. This class is useful for the main application window to fit around your main UI.
QWidget is the base of every GUI element, so it's a catch-all. It's less specific than the other two classes, but in exchange it's more flexible.
You should choose the one that best fits what you are creating. Obviously the way you write the code will be effected, as they are different classes, but all are still QWidgets.

Resources