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
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
MainWindow w;
w.show();
return a.exec();
}
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
MainWindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QMainWindow>
#include <QGraphicsView>
#include <QPainter>
#include <QStyleOptionGraphicsItem>
#include <QWidget>
#include <QGraphicsItem>
namespace Ui
{
class MainWindow;
}
{
public:
{
pixmap.load(source);
}
{
}
{
painter->drawPixmap(0,
0,
100,
100,
pixmap,
0,0,
100,
100);
}
};
{
Q_OBJECT
public:
~MainWindow();
private:
Ui::MainWindow *ui;
MyGraphicsItem* missing;
MyGraphicsItem* notMissing;
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QMainWindow>
#include <QGraphicsView>
#include <QPainter>
#include <QStyleOptionGraphicsItem>
#include <QWidget>
#include <QGraphicsItem>
class QGraphicsScene;
namespace Ui
{
class MainWindow;
}
class MyGraphicsItem : public QGraphicsItem
{
QPixmap pixmap;
public:
MyGraphicsItem(const QString &source, QGraphicsScene *scene) : QGraphicsItem(0, scene)
{
pixmap.load(source);
}
QRectF boundingRect() const
{
return QRectF(0,0, 100, 100);
}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->drawPixmap(0,
0,
100,
100,
pixmap,
0,0,
100,
100);
}
};
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
QGraphicsScene scene;
QGraphicsView *view;
MyGraphicsItem* missing;
MyGraphicsItem* notMissing;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
MainWindow.cpp
#include <QGraphicsScene.h>
#include <QHBoxLayout>
#include <QPixmap>
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
){
ui->setupUi(this);
scene.
setSceneRect(QRectF(-2500,
-2500,
5000,
5000));
view
->setRenderHint
(QPainter::Antialiasing);
view
->setViewportUpdateMode
(QGraphicsView::MinimalViewportUpdate);
layout->addWidget(view);
widget->setLayout(layout);
setCentralWidget(widget);
MyGraphicsItem* missing1 = new MyGraphicsItem(":/missing1", &scene);
MyGraphicsItem* missing2 = new MyGraphicsItem(":/missing2", &scene);
MyGraphicsItem* notMissing = new MyGraphicsItem(":/notmissing", &scene);
MyGraphicsItem* notMissing2 = new MyGraphicsItem(":/notmissing", &scene);
missing1->setPos(0, 0);
missing2->setPos(0, 100);
notMissing->setPos(-100, 0);
notMissing2->setPos(100, 100);
}
MainWindow::~MainWindow()
{
delete ui;
}
#include <QGraphicsScene.h>
#include <QHBoxLayout>
#include <QPixmap>
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
scene.setItemIndexMethod(QGraphicsScene::NoIndex);
scene.setSceneRect(QRectF(-2500, -2500, 5000, 5000));
view = new QGraphicsView(&scene);
view->setRenderHint(QPainter::Antialiasing);
view->setCacheMode(QGraphicsView::CacheBackground);
view->setDragMode(QGraphicsView::RubberBandDrag);
view->setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate);
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(view);
QWidget *widget = new QWidget;
widget->setLayout(layout);
setCentralWidget(widget);
MyGraphicsItem* missing1 = new MyGraphicsItem(":/missing1", &scene);
MyGraphicsItem* missing2 = new MyGraphicsItem(":/missing2", &scene);
MyGraphicsItem* notMissing = new MyGraphicsItem(":/notmissing", &scene);
MyGraphicsItem* notMissing2 = new MyGraphicsItem(":/notmissing", &scene);
missing1->setPos(0, 0);
missing2->setPos(0, 100);
notMissing->setPos(-100, 0);
notMissing2->setPos(100, 100);
}
MainWindow::~MainWindow()
{
delete ui;
}
To copy to clipboard, switch view to plain text mode
resources.qrc
<RCC>
<qresource prefix="/" >
<file alias="notmissing" >notmissing.png</file>
<file alias="missing1" >missing.jpg</file>
<file alias="missing2" >missing2.png</file>
</qresource>
</RCC>
<RCC>
<qresource prefix="/" >
<file alias="notmissing" >notmissing.png</file>
<file alias="missing1" >missing.jpg</file>
<file alias="missing2" >missing2.png</file>
</qresource>
</RCC>
To copy to clipboard, switch view to plain text mode
Minimal.pro
# -------------------------------------------------
# Project created by QtCreator 2009-06-07T06:49:19
# -------------------------------------------------
TARGET = Minimal
TEMPLATE = app
SOURCES += main.cpp \
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
RESOURCES += resources.qrc
# -------------------------------------------------
# Project created by QtCreator 2009-06-07T06:49:19
# -------------------------------------------------
TARGET = Minimal
TEMPLATE = app
SOURCES += main.cpp \
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
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:
Bookmarks