Results 1 to 11 of 11

Thread: QPainter problem (a HW issue perhaps?)

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    Join Date
    May 2009
    Posts
    63
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    12
    Thanked 2 Times in 2 Posts

    Default Re: QPainter problem (a HW issue perhaps?)

    Hi - back again
    Here's a short prog that reproduces the problem.
    In this case, the red square is missing from his, but not mine.

    main.cpp

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "mainwindow.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. MainWindow w;
    8. w.show();
    9. return a.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 


    MainWindow.h

    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QtGui/QMainWindow>
    5. #include <QGraphicsView>
    6. #include <QPainter>
    7. #include <QStyleOptionGraphicsItem>
    8. #include <QWidget>
    9. #include <QGraphicsItem>
    10.  
    11. namespace Ui
    12. {
    13. class MainWindow;
    14. }
    15.  
    16.  
    17. class MyGraphicsItem : public QGraphicsItem
    18. {
    19. QPixmap pixmap;
    20. public:
    21. MyGraphicsItem(const QString &source, QGraphicsScene *scene) : QGraphicsItem(0, scene)
    22. {
    23. pixmap.load(source);
    24. }
    25. QRectF boundingRect() const
    26. {
    27. return QRectF(0,0, 100, 100);
    28. }
    29. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    30. {
    31. painter->drawPixmap(0,
    32. 0,
    33. 100,
    34. 100,
    35. pixmap,
    36. 0,0,
    37. 100,
    38. 100);
    39. }
    40. };
    41.  
    42.  
    43. class MainWindow : public QMainWindow
    44. {
    45. Q_OBJECT
    46.  
    47. public:
    48. MainWindow(QWidget *parent = 0);
    49. ~MainWindow();
    50.  
    51. private:
    52. Ui::MainWindow *ui;
    53. MyGraphicsItem* missing;
    54. MyGraphicsItem* notMissing;
    55. };
    56. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 


    MainWindow.cpp

    Qt Code:
    1. #include <QGraphicsScene.h>
    2. #include <QHBoxLayout>
    3. #include <QPixmap>
    4. #include "mainwindow.h"
    5. #include "ui_mainwindow.h"
    6.  
    7. MainWindow::MainWindow(QWidget *parent)
    8. : QMainWindow(parent), ui(new Ui::MainWindow)
    9. {
    10. ui->setupUi(this);
    11. scene.setItemIndexMethod(QGraphicsScene::NoIndex);
    12. scene.setSceneRect(QRectF(-2500, -2500, 5000, 5000));
    13. view = new QGraphicsView(&scene);
    14. view->setRenderHint(QPainter::Antialiasing);
    15. view->setCacheMode(QGraphicsView::CacheBackground);
    16. view->setDragMode(QGraphicsView::RubberBandDrag);
    17. view->setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate);
    18.  
    19. QHBoxLayout *layout = new QHBoxLayout;
    20. layout->addWidget(view);
    21. QWidget *widget = new QWidget;
    22. widget->setLayout(layout);
    23. setCentralWidget(widget);
    24.  
    25.  
    26. MyGraphicsItem* missing1 = new MyGraphicsItem(":/missing1", &scene);
    27. MyGraphicsItem* missing2 = new MyGraphicsItem(":/missing2", &scene);
    28. MyGraphicsItem* notMissing = new MyGraphicsItem(":/notmissing", &scene);
    29. MyGraphicsItem* notMissing2 = new MyGraphicsItem(":/notmissing", &scene);
    30. missing1->setPos(0, 0);
    31. missing2->setPos(0, 100);
    32. notMissing->setPos(-100, 0);
    33. notMissing2->setPos(100, 100);
    34. }
    35.  
    36. MainWindow::~MainWindow()
    37. {
    38. delete ui;
    39. }
    To copy to clipboard, switch view to plain text mode 

    resources.qrc
    Qt Code:
    1. <RCC>
    2. <qresource prefix="/" >
    3. <file alias="notmissing" >notmissing.png</file>
    4. <file alias="missing1" >missing.jpg</file>
    5. <file alias="missing2" >missing2.png</file>
    6. </qresource>
    7. </RCC>
    To copy to clipboard, switch view to plain text mode 

    Minimal.pro
    Qt Code:
    1. # -------------------------------------------------
    2. # Project created by QtCreator 2009-06-07T06:49:19
    3. # -------------------------------------------------
    4. TARGET = Minimal
    5. TEMPLATE = app
    6. SOURCES += main.cpp \
    7. mainwindow.cpp
    8. HEADERS += mainwindow.h
    9. FORMS += mainwindow.ui
    10. RESOURCES += resources.qrc
    To copy to clipboard, switch view to plain text mode 

    "notmissing.png"


    "missing.jpg"
    Only a link here because the image dimensions are so large (1798x1709x24 48Kb)
    This is the missing "red square" texture source.
    http://img13.imageshack.us/img13/5735/missingz.jpg

    "missing2.png" (1798x1709x24 WARNING 2.2MB)
    Only a link here because the image dimensions and file size are large (1798x1709x24 2.2MB)
    http://img44.imageshack.us/img44/8383/missing2.png

    My result:


    His result:
    Last edited by jonks; 9th June 2009 at 07:08.

Similar Threads

  1. Problem when mixing openGL and QPainter
    By sanjayshelke in forum Qt Programming
    Replies: 9
    Last Post: 21st March 2008, 12:49
  2. use Qpainter to draw lines + problem in my painter
    By ReSu in forum Qt Programming
    Replies: 4
    Last Post: 5th March 2008, 15:44
  3. problem with opengl, zooming, drawpixels, and origin
    By ntp in forum General Programming
    Replies: 0
    Last Post: 22nd February 2008, 21:48
  4. Graphics view display problem.
    By kiranraj in forum Qt Programming
    Replies: 3
    Last Post: 20th July 2007, 07:08
  5. QPainter problem - migration from qt3 [SOLVED]
    By tpomorsk in forum Qt Programming
    Replies: 7
    Last Post: 28th August 2006, 14:43

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
  •  
Qt is a trademark of The Qt Company.