Results 1 to 20 of 21

Thread: QGraphicsView scale question.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #18
    Join Date
    Dec 2006
    Posts
    160
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    33
    Thanked 1 Time in 1 Post

    Default Re: QGraphicsView scale question.

    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:

    Qt Code:
    1. void CDlgSettingsImpl::on_btnZoomIn_clicked(void) {
    2. if (iZoomFactor>=1600)
    3. return;
    4. iZoomFactor *= 2;
    5. lblZoomLevel->setText(QString::number(iZoomFactor)+"%");
    6.  
    7. QGraphicsItem* pPicture;
    8. QPointF mapped1, mapped2;
    9. QRectF f;
    10.  
    11. pPicture = grphVwOriginalPicture->items().first();
    12. pPicture->scale(2, 2);
    13. f = pPicture->boundingRect();
    14. mapped1 = pPicture->mapToScene(f.topLeft());
    15. mapped2 = pPicture->mapToScene(f.bottomRight());
    16. grphVwOriginalPicture->centerOn((mapped2.x()-mapped1.x())/2, (mapped2.y()-mapped1.y())/2);
    17. }
    18. void CDlgSettingsImpl::on_btnZoomOut_clicked(void) {
    19. if (iZoomFactor<=25)
    20. return;
    21. iZoomFactor /= 2;
    22. lblZoomLevel->setText(QString::number(iZoomFactor)+"%");
    23.  
    24. QGraphicsItem* pPicture;
    25. QPointF mapped1, mapped2;
    26. QRectF f;
    27.  
    28. pPicture = grphVwOriginalPicture->items().first();
    29. pPicture->scale(.5, .5);
    30. f = pPicture->boundingRect();
    31. mapped1 = pPicture->mapToScene(f.topLeft());
    32. mapped2 = pPicture->mapToScene(f.bottomRight());
    33. grphVwOriginalPicture->centerOn((mapped2.x()-mapped1.x())/2, (mapped2.y()-mapped1.y())/2);
    34. }
    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):
    Qt Code:
    1. // Create the original preview objects.
    2. grphScOriginal = new QGraphicsScene(this);
    3. grphVwOriginalPicture = new QGraphicsView(grphScOriginal, this);
    4. grphVwOriginalPicture->setFrameShape(QFrame::Panel);
    5. grphVwOriginalPicture->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    6. grphVwOriginalPicture->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    7. grphVwOriginalPicture->setDragMode(QGraphicsView::ScrollHandDrag);
    8. grphVwOriginalPicture->setBackgroundBrush(Qt::darkGray);
    9. fillPreviewFromPlane(grphScOriginal, pInPlane);
    10.  
    11. void CDlgSettingsImpl::fillPreviewFromPlane(QGraphicsScene* grphScToFill, CARGBPlane* pPlane) {
    12. QList<QGraphicsItem*> lstItems = grphScToFill->items();
    13. while (!lstItems.isEmpty()) {
    14. QGraphicsItem* pCurrentItem = lstItems.takeFirst();
    15. grphScToFill->removeItem(pCurrentItem);
    16. delete pCurrentItem;
    17. }
    18. QImage cImage = QImage(pPlane->Width(), pPlane->Height(), QImage::Format_RGB32);
    19. byte* fR = pPlane->fR;
    20. byte* fG = pPlane->fG;
    21. byte* fB = pPlane->fB;
    22. for (int iY=0; iY<pPlane->Height(); iY++)
    23. for (int iX=0; iX<pPlane->Width(); iX++)
    24. cImage.setPixel(iX, iY, qRgb(*fR++, *fG++, *fB++));
    25. grphScToFill->addPixmap(QPixmap::fromImage(cImage, Qt::ColorOnly | Qt::ThresholdDither));
    26. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by hickscorp; 15th April 2007 at 01:26.

Similar Threads

  1. Replies: 1
    Last Post: 15th March 2007, 21:45
  2. Using QGraphicsView with model/view programming
    By JLP in forum Qt Programming
    Replies: 3
    Last Post: 29th January 2007, 12:04
  3. Question regarding how to paint after zoom.
    By JonathanForQT4 in forum Qt Programming
    Replies: 2
    Last Post: 26th January 2007, 16:34
  4. Efficient Scaling and Rotating of QGraphicsView
    By forrestfsu in forum Qt Programming
    Replies: 10
    Last Post: 12th December 2006, 17:28
  5. QGraphicsView scale function
    By forrestfsu in forum Qt Programming
    Replies: 2
    Last Post: 12th October 2006, 15:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.