Results 1 to 5 of 5

Thread: Having trouble with QGraphicsView

  1. #1
    Join Date
    Aug 2009
    Posts
    10
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Having trouble with QGraphicsView

    I am having trouble displaying an image (or anything) in a QGraphicsView

    I have a frame named mainwindow which contains simply a QGraphicsView widget named mainGraphics

    I have an image named imageMap.bmp which I have added to the resource file

    When I run the program, the QGraphicsView mainGraphics is blank.... just a white space in the frame..... if I change the setSceneRect param, the scrollable area does change size, so I am def changing parameters on the correct item, but just none of the graphics will show up...???

    The code in mainwindow.cpp is as follows:

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <QtGui>
    4.  
    5. MainWindow::MainWindow(QWidget *parent)
    6. : QMainWindow(parent), ui(new Ui::MainWindow)
    7. {
    8. ui->setupUi(this);
    9.  
    10. ui->mainGraphics->setSceneRect(0,0,500,500);
    11. QPixmap back(":/images/imageMap.bmp");
    12. ui->mainGraphics->setBackgroundBrush(back);
    13.  
    14.  
    15. scene.addText("Some text");
    16. scene.addLine(10,10,200,200);
    17.  
    18. ui->mainGraphics->setScene(&scene);
    19. ui->mainGraphics->show();
    20.  
    21.  
    22.  
    23.  
    24. }
    25.  
    26. MainWindow::~MainWindow()
    27. {
    28. delete ui;
    29. }
    To copy to clipboard, switch view to plain text mode 

    a file named main.cpp contains the main() function which starts the program

  2. #2
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Having trouble with QGraphicsView

    may be the scene is obscuring the background image of the view ... make QGraphicsScene little transperent using setOpacity() ..

    also use QGraphicsView::setCacheMode(CacheBackground);
    "Behind every great fortune lies a crime" - Balzac

  3. #3
    Join Date
    Aug 2009
    Posts
    10
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Having trouble with QGraphicsView

    I have set the cach mode to cachBackground but it still doesn't make any difference.... nothing is showing up....

    Also, the QGraphicsScene does not have a setOpacity() function, that is only implemented by QGraphicsItem.....

    I don't think it is an opacity issue as even the text and line is not showing up....

  4. #4
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Having trouble with QGraphicsView

    if not setOpacity() then alpha value u can set in QColor ()

    ok did u see the padnavigator example ... they set pixmap for the graphicsView ... see where the problem arise ..
    Last edited by wagmare; 11th August 2009 at 12:03.
    "Behind every great fortune lies a crime" - Balzac

  5. #5
    Join Date
    Aug 2009
    Posts
    10
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Having trouble with QGraphicsView

    I really appreciate your help wagmare, but unfortunaltely I am still having problems...

    I have had a look through the padnavigator example but I dont see where I have implemented it any different apart from the fact that they made a subclass of QGraphicsView...


    Also... if I remove the QGraphicsScene element, it still does not show a background.... so its not an opacity problem

Similar Threads

  1. Replies: 0
    Last Post: 5th March 2009, 07:54
  2. QGraphicsView setRenderHints() problem
    By roshlame in forum Qt Programming
    Replies: 0
    Last Post: 3rd December 2008, 19:42
  3. QGraphicsView and embeded widgets
    By bunjee in forum Qt Programming
    Replies: 10
    Last Post: 12th October 2008, 08:43
  4. Problem determining size of QGraphicsView
    By Bocki in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2008, 15:54
  5. Replies: 3
    Last Post: 12th February 2008, 22:17

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.