Till Oliver Knoll <till.oliver.kn...@gmail.com> wrote .. > > Am 08.06.2012 um 04:19 schrieb "Waitman Gobble" <uzi...@da3m0n8t3r.com>: > > > ... > > gs->addPixmap(pm); > > gs->setSceneRect(pm.rect()); //set the size using Andre's way. > > Hmm, that's odd. While your code makes perfect sense from what I understand > from > the previously linked Qt docs is that it should also work with a "null" > QRectF. > And yes, I really meant "null" as in "QRectF::isNull() returns true" (the > c'tor > creates a "null" QRectF, just as was previously shown in André's code). > > But apparently that doesn't work and hence seems to be a bug. > > Imagine you would clear the scene and add /several/ new objects to it. Off > course > you could always calculate the bounding box of those objects yourself by > iterating > over them - but that is exactly the purpose of sceneRect(), if the current > rectangle > is a "null" one (at least according to the docs). > > > By the way: what do you do with your single pixmap in the graphics scene? Do > you > want to be able to zoom in? Otherwise why not use a simple QPainter to draw it > onto some given widget? > > Cheers, > Oliver > _______________________________________________ > Interest mailing list > Interest@qt-project.org > http://lists.qt-project.org/mailman/listinfo/interest
Hi, Maybe it's a bug? Setting to Null QRectF did not seem to update the size. here's version/os info. $ uname -a FreeBSD hunny.waitman.net 10.0-CURRENT FreeBSD 10.0-CURRENT #0: Sat Jun 2 01:25:21 PDT 2012 root@:/usr/obj/usr/src/sys/KEYSHIA amd64 $ qmake-qt4 --version QMake version 2.01a Using Qt version 4.8.1 in /usr/local/lib/qt4 I selected the QGraphicsView / QGraphicsScene / QPixMap because it seems to be the best to allow the user the zoom in/out. (?) At the moment the idea is to use a Horizontal Slider for zoom but i'm not yet decided and haven't gotten that far with it. Still working out the details. void MainWindow::loadImage() { QString path; QList<QUrl> urls; urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::HomeLocation)) << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::DesktopLocation)) << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation)) << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::PicturesLocation)); QFileDialog dialog; dialog.setSidebarUrls(urls); dialog.setFileMode(QFileDialog::ExistingFile); dialog.setViewMode(QFileDialog::Detail); dialog.setAcceptMode(QFileDialog::AcceptOpen); dialog.setLabelText(QFileDialog::FileName,"Choose an image file to open"); if (dialog.exec()) { QStringList fileNames = dialog.selectedFiles(); path = fileNames[0]; ui->lineEdit->setText( path ); QPixmap pm(path); gs->clear(); gs->addPixmap(pm); gs->setSceneRect(pm.rect()); gv->setScene(gs); gv->update(); if ((gs->width() > gv->width()) || (gs->height() > gv->height())) { gv->fitInView(gv->sceneRect(),Qt::KeepAspectRatio); int hv = qCeil(gv->width()/gs->width()) * 100; ui->horizontalSlider->setMaximum(hv*2); ui->horizontalSlider->setSliderPosition(hv); } else { gv->resetTransform(); } } } Maybe QPainter is a better way, I'll check it out. I'm just working with one image a time. Thank you, -- Waitman Gobble San Jose California USA
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest