How to add Graphics Scene/Graphics View to Widget?
Qt GraphicsScene on Widget
1.2k views Asked by AudioBubble At
2
There are 2 answers
0
On
Thank you so much for your answer. This also it works.
#include <QApplication>
#include <QWidget>
#include <QVBoxLayout>
#include <QGraphicsView>
#include <QGraphicsTextItem>
#include <QGraphicsScene>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget *window = new QWidget;
window->resize(300, 200);
QVBoxLayout *layout = new QVBoxLayout(window);
QGraphicsScene *scene = new QGraphicsScene(window);
QGraphicsView *view = new QGraphicsView(scene);
QGraphicsTextItem *text = scene->addText("Hello World");
layout->addWidget(view);
window->show();
return a.exec();
}
This is my Solution:
Output: