Qt GLWidget how to draw text - qt

before I used Qt and customized my own Widget which is inherits from QGLWidget
i used OpenGl in standard projects and free glut.
by doing this, I used glutBitmapChracter but now in Qt there is no need to manage windows because I created customize widget with gui.
so how can I draw text on the widget?
if I want to include the free glut and use glutBitmapCharacter I nedd also to init the glut and im getting confused?
is there any other way or do I have to use external library?

You are using a QGLWidget and want to draw 2D text on top of the 3D scene?
glutBitmapCharacter should still work in a QGLWidget, just like other GL library code. I do not think you need to call glutInit to use the GLUT character drawing functions.
Or you could use the Qt 2D text drawing methods (QPainter) to draw text on top of your QGLWidget. A Qt book or online documentation will explain how to do this. (I have the books on Qt programming by Blanchette and Summerfield, and can recommend them.)
Hope this helps.

Related

How to use MFC Ribbon in the Qt application?

I am started to implement the microsoft ribbon interface on the qt library but finally understand that it is too complex task for me.
So I decided to use native mfc ribbon inside my application.
But the main question is how to do this?
Qt does not have native "MFC Ribbon", but the closest thing available is QTabWidget. You can use CSS stylesheets to make it look somewhat like MFC Ribbon. If you want exact look of MFC Ribbon, then you need to reimplement paintEvent and draw the widget as you need.
Some CSS Examples to get you started.
1) https://gist.github.com/espdev/4f1565b18497a42d317cdf2531b7ef05
2) http://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qtabwidget-and-qtabbar
There is a pre-built library called QtitanRibbon, although it's not free take a look into the free trial version.
Also check out this answer

How to use OpenGL in QT Creator

I am working on OpenGL to create a GUI .I want to create some tabs which will help me to display different things in different windows. How is this possible using OpenGL? I read in some articles that we can use QT for that. Since I have already developed some of the GUI part in OpenGL using GLUT library ,is it possible to use the same code in QT? If so brief me how to make settings for OpenGL libraries in QT creator.
In my GUI I am trying to create a Car which is following a track.
I think you might be mixing some things up: OpenGL is a API with which you can instruct drivers to draw visual primitives, like lines, boxes, 3D triangles, pictures from buffer onto a render plane.
GLUT is a library that gives you a minimal environment around that, ie. it handles creating a window etc.
Neither of them are high-level UI description tools. Qt is really most likely what you want, as it will not only give you things like tab widgets etc, but also a feature-rich framework to do things like defining what should happen when you click a button, close a window etc.
There's a lot of examples of OpenGL usage within Qt widgets. In fact, a lot of visualization frontends use Qt and OpenGL. Qt has extensive documentation on how to generate OpenGL contextes and draw inside Qt applications.

Custom real-time drawing in Qt5 and Qt Quick 2

I have been looking far and wide to find out how, if it’s possible, you can fill a particular area in a QML screen with an OpenGL context and do custom OpenGL only in that context. I’ve seen plenty of demos where the QML components like buttons, etc lay on top or below a screen-wide OpenGL context (as is typically required by games), but I’d like to be able to situate several distinct OpenGL contexts within QML and have the QML file define how large they are, where they are positioned, etc.
Now, since Qt 5 is all OpenGL under the hood, it makes me wonder if using a Canvas element with custom drawing via javascript could result in similar rendering performance as custom OpenGL? This would be a meaningful alternative but it’s not clear to me how the javascript drawing is handled via runtime compared to custom OpenGL drawing.
What is it that you want to draw? QQuickPaintedItem may be the simplest way to go about it. When you're using QOpenGLFramebufferObject as the target, the painter will use OpenGL to paint the texture. It might be easier than writing your own OpenGL code if all you're doing is 2D.

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.

Need an example using std::vector in Qt

I have a UI (used Qt creator) that I am working on that creates opengl models at runtime, such that when I click a button it draws a cube or any other model.
Can anyone please show me an example of how the c++ container class std::vector can be used for this in Qt ?
Why do you want to use std::vector in Qt. Are they pure C++ objects. Look into QList, QVector and variants (they also offer STL like iterators).
I can think of no reason why you cannot use std::vector in a Qt project.

Resources