Hello sorry for the delay 
With your code, i have the very same problem. The item is "stuck" to the top left corner, and only can be dragged off-screen when it is little. When it's bigger than the viewable area, it's draggable but can be sragged off-screen in the top left direction too.
There comes a preview of my code:
void CDlgSettingsImpl::on_btnZoomIn_clicked(void) {
if (iZoomFactor>=1600)
return;
iZoomFactor *= 2;
lblZoomLevel
->setText
(QString::number(iZoomFactor
)+"%");
pPicture = grphVwOriginalPicture->items().first();
pPicture->scale(2, 2);
f = pPicture->boundingRect();
mapped1 = pPicture->mapToScene(f.topLeft());
mapped2 = pPicture->mapToScene(f.bottomRight());
grphVwOriginalPicture->centerOn((mapped2.x()-mapped1.x())/2, (mapped2.y()-mapped1.y())/2);
}
void CDlgSettingsImpl::on_btnZoomOut_clicked(void) {
if (iZoomFactor<=25)
return;
iZoomFactor /= 2;
lblZoomLevel
->setText
(QString::number(iZoomFactor
)+"%");
pPicture = grphVwOriginalPicture->items().first();
pPicture->scale(.5, .5);
f = pPicture->boundingRect();
mapped1 = pPicture->mapToScene(f.topLeft());
mapped2 = pPicture->mapToScene(f.bottomRight());
grphVwOriginalPicture->centerOn((mapped2.x()-mapped1.x())/2, (mapped2.y()-mapped1.y())/2);
}
void CDlgSettingsImpl::on_btnZoomIn_clicked(void) {
if (iZoomFactor>=1600)
return;
iZoomFactor *= 2;
lblZoomLevel->setText(QString::number(iZoomFactor)+"%");
QGraphicsItem* pPicture;
QPointF mapped1, mapped2;
QRectF f;
pPicture = grphVwOriginalPicture->items().first();
pPicture->scale(2, 2);
f = pPicture->boundingRect();
mapped1 = pPicture->mapToScene(f.topLeft());
mapped2 = pPicture->mapToScene(f.bottomRight());
grphVwOriginalPicture->centerOn((mapped2.x()-mapped1.x())/2, (mapped2.y()-mapped1.y())/2);
}
void CDlgSettingsImpl::on_btnZoomOut_clicked(void) {
if (iZoomFactor<=25)
return;
iZoomFactor /= 2;
lblZoomLevel->setText(QString::number(iZoomFactor)+"%");
QGraphicsItem* pPicture;
QPointF mapped1, mapped2;
QRectF f;
pPicture = grphVwOriginalPicture->items().first();
pPicture->scale(.5, .5);
f = pPicture->boundingRect();
mapped1 = pPicture->mapToScene(f.topLeft());
mapped2 = pPicture->mapToScene(f.bottomRight());
grphVwOriginalPicture->centerOn((mapped2.x()-mapped1.x())/2, (mapped2.y()-mapped1.y())/2);
}
To copy to clipboard, switch view to plain text mode
Can it be a bug with my QT installation? i havnt tested any of the QGraphics framework on linux, so i'm not sure if it's windows only ...
Pierre.
[EDIT:] Maybe the error is here, so here comes how i create the QGraphicsScene & View stuff (In the dialog's constructor):
// Create the original preview objects.
grphVwOriginalPicture
->setFrameShape
(QFrame::Panel);
grphVwOriginalPicture->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
grphVwOriginalPicture->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
grphVwOriginalPicture
->setDragMode
(QGraphicsView::ScrollHandDrag);
grphVwOriginalPicture->setBackgroundBrush(Qt::darkGray);
fillPreviewFromPlane(grphScOriginal, pInPlane);
void CDlgSettingsImpl
::fillPreviewFromPlane(QGraphicsScene* grphScToFill, CARGBPlane
* pPlane
) { QList<QGraphicsItem*> lstItems = grphScToFill->items();
while (!lstItems.isEmpty()) {
grphScToFill->removeItem(pCurrentItem);
delete pCurrentItem;
}
byte* fR = pPlane->fR;
byte* fG = pPlane->fG;
byte* fB = pPlane->fB;
for (int iY=0; iY<pPlane->Height(); iY++)
for (int iX=0; iX<pPlane->Width(); iX++)
cImage.setPixel(iX, iY, qRgb(*fR++, *fG++, *fB++));
grphScToFill
->addPixmap
(QPixmap::fromImage(cImage, Qt
::ColorOnly | Qt
::ThresholdDither));
}
// Create the original preview objects.
grphScOriginal = new QGraphicsScene(this);
grphVwOriginalPicture = new QGraphicsView(grphScOriginal, this);
grphVwOriginalPicture->setFrameShape(QFrame::Panel);
grphVwOriginalPicture->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
grphVwOriginalPicture->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
grphVwOriginalPicture->setDragMode(QGraphicsView::ScrollHandDrag);
grphVwOriginalPicture->setBackgroundBrush(Qt::darkGray);
fillPreviewFromPlane(grphScOriginal, pInPlane);
void CDlgSettingsImpl::fillPreviewFromPlane(QGraphicsScene* grphScToFill, CARGBPlane* pPlane) {
QList<QGraphicsItem*> lstItems = grphScToFill->items();
while (!lstItems.isEmpty()) {
QGraphicsItem* pCurrentItem = lstItems.takeFirst();
grphScToFill->removeItem(pCurrentItem);
delete pCurrentItem;
}
QImage cImage = QImage(pPlane->Width(), pPlane->Height(), QImage::Format_RGB32);
byte* fR = pPlane->fR;
byte* fG = pPlane->fG;
byte* fB = pPlane->fB;
for (int iY=0; iY<pPlane->Height(); iY++)
for (int iX=0; iX<pPlane->Width(); iX++)
cImage.setPixel(iX, iY, qRgb(*fR++, *fG++, *fB++));
grphScToFill->addPixmap(QPixmap::fromImage(cImage, Qt::ColorOnly | Qt::ThresholdDither));
}
To copy to clipboard, switch view to plain text mode
Bookmarks