PDA

View Full Version : How to make MDI editor with QGraphicsView support



Kuzemko
13th February 2007, 06:59
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.

aamer4yu
13th February 2007, 07:11
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..

fullmetalcoder
13th February 2007, 08:37
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 );
}

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() (http://doc.trolltech.com/4.2/qwidget#show) method is not calledhere is what I suggest :



SymbolEditor::SymbolEditor(QWidget *parent)
: QGraphicsView(parent)
{
QGraphicsScene *symbolEditorScene = new QGraphicsScene;
symbolEditorScene->addText("Hello");

setScene(symbolEditorScene);
setRenderHint(QPainter::Antialiasing);
setCacheMode(QGraphicsView::CacheBackground);

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()));

setWindowIcon(QPixmap(":/images/document.png"));
setAttribute(Qt::WA_DeleteOnClose);

show();
}
Hope this helps. :)

Kuzemko
14th February 2007, 05:15
Thanks, It work!

Kuzemko
14th February 2007, 18:31
I need realize in the program, that 1 pixel on the screen corresponded 0.001mm on a paper. Help me as it to realize.