2017-05-29 91 views
0

我的工作環境:的Qt 5.8 MSVC2015 64位,QT GraphicsView,Windows 7的64位QT的QGraphicsView放大,縮小發行

我有如下派生我的課:

class MainWindow : public QMainWindow 
class mySquare : public QGraphicsRectItem 
class GraphicsView : public QGraphicsView 
class Scene : public QGraphicsScene 

我有在裏面繪製帶有文字的Sqaure。 變焦的變焦&出我用下面的代碼:

void GraphicsView::mouseMoveEvent(QMouseEvent *event) 
{ 
    //temp raise mouse movement signal start 
    QPointF movment = mapToScene (event->pos()); 
    emit sendMousePoint(movment); 

    if (_pan) // it get enable when control button is pressed. 
    { 
     horizontalScrollBar()->setValue(horizontalScrollBar()->value() - (event->x() - _panStartX)); 
     verticalScrollBar()->setValue(verticalScrollBar()->value() - (event->y() - _panStartY)); 
     _panStartX = event->x(); 
     _panStartY = event->y(); 
     event->accept(); 
    // qDebug() <<"Mouse X" << QString::number(event->pos().x()) << " Y:" << QString::number(event->pos().y()); 
     return; 
    } 
    //temp raise mouse movement signal end 
    event->ignore(); 
    QGraphicsView::mousePressEvent(event); 

} 

但是,當我在&縮小它超出焦點&的創建白色空白屏幕。

任何線索我失去了什麼在放大& out代碼?

回答

0

我已經搞亂了mySquare :: paint代碼的代碼。

這裏是我的固定碼:

void mySquare::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) 
{ 
    Q_UNUSED(widget); 
    painter->save(); 
    painter->setPen(Qt::darkBlue); 
    painter->setBrush(Qt::NoBrush); 
    const qreal lod = option->levelOfDetailFromTransform(painter->worldTransform()); 

    if((lod>_minlod) && (lod<=_maxlod)) 
    { 

    } 
    else 
    { 
     QRectF rect(0,0,_width,_height); 
     painter->drawRect(rect); 
     return; 
    } 

    if((_level==0) && (_row==0) && (_col==0)) 
    { 
     qDebug()<<" Level: "<<_level<<" lod:"<<lod; 
    } 
    QRectF rect(0,0,_width,_height); 
    painter->drawRect(rect); 
    QString text1= QString("I am at level : %1 , Row: %2, Col : %3").arg(_level).arg(_row).arg(_col); 
    painter->drawText(QRectF(40, 40, _width -20, _height -20),text1); 
    painter->restore();