How to make MDI editor with QGraphicsView support
Hello All!
I am a notice in Qt-programming.
I need MDI editor with support QGraphicsScene and QGraphicsView. I see example in Qt docs, and make some change to it.
But I have a wrong result.
In constructor I add text "Hello" to the scene, but I not see it on the screen.
I think that I write wrong constructor
SymbolEditor::SymbolEditor(QWidget *parent)
: QGraphicsView(parent)
{
QGraphicsScene symbolEditorScene;
symbolEditorScene.addText("Hello");
QGraphicsView symbolEditorView(&symbolEditorScene);
symbolEditorView.setRenderHint(QPainter::Antialias ing);
symbolEditorView.setCacheMode(QGraphicsView::Cache Background);
//symbolEditorView.show();
symbolAction = new QAction(this);
symbolAction->setCheckable(true);
connect(symbolAction, SIGNAL(triggered()), this, SLOT(show()));
connect(symbolAction,SIGNAL(triggered()), this,SLOT(setFocus()));
isUntitled = true;
modified=false;
selected=false;
fileSymbolFilters = tr("Файлы символов УГО (*.ksef)\n"
"Все файлы (*)");
connect(this, SIGNAL(contentsChanged()),this, SLOT(documentWasModified()));
symbolEditorView.setWindowIcon(QPixmap(":/images/document.png"));
symbolEditorView.setAttribute(Qt::WA_DeleteOnClose );
}
And when I close active window it closed but I can see it in windows list in menu.
Please help me.
Re: How to make MDI editor with QGraphicsView support
As i can see u have inherited symbolEditor from QGraphicsView. So this represents a view class.
U need to set the scene for this view from outside the class..
such as view->setScene(scene);
can u give the class declaration of symboEditor?? will help to know ur design..
Re: How to make MDI editor with QGraphicsView support
Quote:
Originally Posted by
Kuzemko
Code:
SymbolEditor
::SymbolEditor(QWidget *parent
){
symbolEditorScene.addText("Hello");
symbolEditorView.
setRenderHint(QPainter::Antialiasing);
//symbolEditorView.show();
symbolAction->setCheckable(true);
connect(symbolAction, SIGNAL(triggered()), this, SLOT(show()));
connect(symbolAction,SIGNAL(triggered()), this,SLOT(setFocus()));
isUntitled = true;
modified=false;
selected=false;
fileSymbolFilters = tr("Файлы символов УГО (*.ksef)\n"
"Все файлы (*)");
connect(this, SIGNAL(contentsChanged()),this, SLOT(documentWasModified()));
symbolEditorView.
setWindowIcon(QPixmap(":/images/document.png"));
symbolEditorView.setAttribute(Qt::WA_DeleteOnClose);
}
There's something wrong in your code : your SymbolEditor class inherits from QGraphicsView but creates another QGraphicsView inside its constructor... Moreover the internaly created QGraphicsView has no chance to be seen because :- it is allocated on heap (i.e. it's not a pointer...) and will be destroyed just at the end of the constructor...
- the QWidget::show() method is not called
here is what I suggest :
Code:
SymbolEditor
::SymbolEditor(QWidget *parent
){
symbolEditorScene->addText("Hello");
setScene(symbolEditorScene);
symbolAction->setCheckable(true);
connect(symbolAction, SIGNAL(triggered()), this, SLOT(show()));
connect(symbolAction,SIGNAL(triggered()), this,SLOT(setFocus()));
isUntitled = true;
modified=false;
selected=false;
fileSymbolFilters = tr("Файлы символов УГО (*.ksef)\n"
"Все файлы (*)");
connect(this, SIGNAL(contentsChanged()),this, SLOT(documentWasModified()));
setWindowIcon
(QPixmap(":/images/document.png"));
setAttribute(Qt::WA_DeleteOnClose);
show();
}
Hope this helps. :)
Re: How to make MDI editor with QGraphicsView support
Re: How to make MDI editor with QGraphicsView support
I need realize in the program, that 1 pixel on the screen corresponded 0.001mm on a paper. Help me as it to realize.