c++ - How to attach a signal to qPixmap? -
i'm creating application using c++ qt , want load multiple images. attach signal each image can enable or disable them afterwards.
any help?
edit 1:
imagedlg = new qfiledialog(); imagelist = imagedlg->getopenfilenames(this, tr("open document"), qdir::currentpath(), tr("image files (*.png *.jpg);;all files (*.*)")); qstring imagename; int x = -50; int y = -50; int n = 1; double size = imagelist.size(); if(imagelist.isempty()) return; scene->clear(); setcursor(qt::waitcursor); foreach(imagename,imagelist) { double val = (n/size)*100; ui->progressbar->setvalue((int)val); image.load(imagename,"4",qt::autocolor); image = image.scaled(100,100,qt::keepaspectratio,qt::fasttransformation); imagenames.push_back(imagename.tostdstring()); // scene->setscenerect(x,y,100,100); item = scene->addpixmap(image); item->setpos(x,y); x = x + 110; if(n%4 == 0) { x = -50; y = y + 90; } n++; } //ui->label_2->settext(strcat("10","image(s) loaded successfully")); setcursor(qt::arrowcursor); ui->imagegraphicsview->setscene(scene);
you should storing qgraphicspixmapitem*
pointers you're getting from:
scene->addpixmap();
(use e.g. qlist<qgraphicspixmapitem*>
or container of choice.)
these objects displayed on scene. can change appearance, show or hide them, change opacity etc. through pointers.
look @ documentation qgraphicsitem
detailed information how can manipulate these items.
qgraphicsitem
doesn't inherit qobject
, doesn't have signals or slots (the classes derived don't either). if want handle mouse events, you'll need create custom graphics item (derived qgraphicspixmapitem
example) , re-implement event handling functions you're interested in.
look @ elastic nodes example sample of how can handle mouse events graphics items.
Comments
Post a Comment