Results 1 to 5 of 5

Thread: How to make MDI editor with QGraphicsView support

  1. #1
    Join Date
    Jan 2007
    Location
    UKRAINE
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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..

  3. #3
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to make MDI editor with QGraphicsView support

    Quote Originally Posted by Kuzemko View Post
    Qt Code:
    1. SymbolEditor::SymbolEditor(QWidget *parent)
    2. : QGraphicsView(parent)
    3. {
    4. QGraphicsScene symbolEditorScene;
    5. symbolEditorScene.addText("Hello");
    6. QGraphicsView symbolEditorView(&symbolEditorScene);
    7. symbolEditorView.setRenderHint(QPainter::Antialiasing);
    8. symbolEditorView.setCacheMode(QGraphicsView::CacheBackground);
    9. //symbolEditorView.show();
    10. symbolAction = new QAction(this);
    11. symbolAction->setCheckable(true);
    12. connect(symbolAction, SIGNAL(triggered()), this, SLOT(show()));
    13. connect(symbolAction,SIGNAL(triggered()), this,SLOT(setFocus()));
    14.  
    15. isUntitled = true;
    16. modified=false;
    17. selected=false;
    18. fileSymbolFilters = tr("Файлы символов УГО (*.ksef)\n"
    19. "Все файлы (*)");
    20. connect(this, SIGNAL(contentsChanged()),this, SLOT(documentWasModified()));
    21.  
    22. symbolEditorView.setWindowIcon(QPixmap(":/images/document.png"));
    23. symbolEditorView.setAttribute(Qt::WA_DeleteOnClose);
    24. }
    To copy to clipboard, switch view to plain text mode 
    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 :

    Qt Code:
    1. SymbolEditor::SymbolEditor(QWidget *parent)
    2. : QGraphicsView(parent)
    3. {
    4. QGraphicsScene *symbolEditorScene = new QGraphicsScene;
    5. symbolEditorScene->addText("Hello");
    6.  
    7. setScene(symbolEditorScene);
    8. setRenderHint(QPainter::Antialiasing);
    9. setCacheMode(QGraphicsView::CacheBackground);
    10.  
    11. symbolAction = new QAction(this);
    12. symbolAction->setCheckable(true);
    13. connect(symbolAction, SIGNAL(triggered()), this, SLOT(show()));
    14. connect(symbolAction,SIGNAL(triggered()), this,SLOT(setFocus()));
    15.  
    16. isUntitled = true;
    17. modified=false;
    18. selected=false;
    19. fileSymbolFilters = tr("Файлы символов УГО (*.ksef)\n"
    20. "Все файлы (*)");
    21. connect(this, SIGNAL(contentsChanged()),this, SLOT(documentWasModified()));
    22.  
    23. setWindowIcon(QPixmap(":/images/document.png"));
    24. setAttribute(Qt::WA_DeleteOnClose);
    25.  
    26. show();
    27. }
    To copy to clipboard, switch view to plain text mode 
    Hope this helps.
    Last edited by fullmetalcoder; 13th February 2007 at 07:38. Reason: fixed a typo in the code...
    Current Qt projects : QCodeEdit, RotiDeCode

  4. #4
    Join Date
    Jan 2007
    Location
    UKRAINE
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to make MDI editor with QGraphicsView support

    Thanks, It work!

  5. #5
    Join Date
    Jan 2007
    Location
    UKRAINE
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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.

Similar Threads

  1. Compile QT4.2.2 with MySQL on Mac OS
    By asd in forum Installation and Deployment
    Replies: 7
    Last Post: 12th February 2007, 14:50
  2. Qt will not be built with XShape support.
    By manfredfr in forum Installation and Deployment
    Replies: 4
    Last Post: 14th March 2006, 08:26

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.