1

When I add QGraphicsPixmapItem to scene and after first mouse click program freeze for long. Why? Or how i can exclude this from Qt's inner computations (if only i know what happens behind..)

*.h

#include <QtWidgets/QMainWindow>
#include "ui_bigqgraphicsscene.h"

class BigQGraphicsScene : public QMainWindow
{
    Q_OBJECT

public:
    BigQGraphicsScene(QWidget *parent = 0);
    ~BigQGraphicsScene();

private slots:
    void on_pushButton_clicked();

private:
    Ui::BigQGraphicsSceneClass ui;

    QImage imgOrig;
};

*.cpp

#include "bigqgraphicsscene.h"
#include <QFileDialog>
#include <QSet>
#include <QDebug>
#include <QGraphicsPixmapItem>

BigQGraphicsScene::BigQGraphicsScene(QWidget *parent)
    : QMainWindow(parent)
{
    ui.setupUi(this);
    ui.graphicsView->setScene(new QGraphicsScene());
}

BigQGraphicsScene::~BigQGraphicsScene(){}

void BigQGraphicsScene::on_pushButton_clicked()
{
    QString s = "d:/!Qt/ImageNumber/BigQGraphicsScene/TestPic/fastole_bdr.png";

    if (s.length())
    {
        imgOrig.load(s);        
       QGraphicsPixmapItem *itm = new QGraphicsPixmapItem();

       itm->setPixmap(QPixmap::fromImage(imgOrig));

        ui.graphicsView->scene()->setItemIndexMethod(QGraphicsScene::NoIndex);
       ui.graphicsView->scene()->addItem(itm);

       ui.graphicsView->scene()->setSceneRect( imgOrig.rect() );
    }
}

scene()->setItemIndexMethod(QGraphicsScene::NoIndex); - not help...

almost transparent pix for example - fastole_bdr.png

user3444737
  • 41
  • 1
  • 7
  • Freeze for how long? One second? One hour? – Matt Jordan Feb 24 '16 at 22:15
  • freeze about 20 seconds for this uploaded pic with no other items on scene. But I need pixmaps about 5000x5000 or even 10000x10000 and more. At least, user have to has this opportunity (yes, if he has enough memory ;) ) – user3444737 Feb 25 '16 at 01:00

1 Answers1

0

Can you background load your image? You're reading from disk and then processing the image into whatever format QT uses internally on the UI thread, so it's not particularly surprising that the application becomes unresponsive for larger images.

Jarra McIntyre
  • 1,265
  • 8
  • 13
  • No, image loads from disk normaly, with usually expected delay.. Not immidiately of course. Depends by size. Problem exactly with adding big but transparent image to QGraphicsScene. – user3444737 Feb 25 '16 at 01:04
  • Have you timed the operations to precisely determine where the delays are occurring? In particular I would time: imgOrd.load(), QPixmap::fromImage(imgOrig), itm->setPixmap(), ui.graphicsView->scen()->addItem(itm) and ui.graphicsView->scene()->setSceneRect(imgOrig.rect()) – Jarra McIntyre Feb 25 '16 at 01:25
  • Delay occuring right after any first click on scene after inserting this strange item. Initially I can click any buttons, resize or do any other things with interface if only not toch aera inside graphicsview. When click there for first time then starts some Qt's magic. When magic completed all becomes good again. – user3444737 Feb 25 '16 at 01:34
  • So the delay doesn't occur in on_pushButton_clicked()? You can add the image but later on when you click the graphic itself there is a delay? – Jarra McIntyre Feb 25 '16 at 02:11
  • Yes, only after click. I think it is something about indexing items to detect selection. If i add some alpha to transparent areas even image still look transparent but for computer it becomes big solid rectangle, not graph of single dots. I can't select anything under borders-image but no delays. Well, i invent how to not use separate item only for borders. Thanks for your attention) – user3444737 Feb 25 '16 at 07:39