N
N
Nikita Lubchich2013-12-09 12:15:10
Qt
Nikita Lubchich, 2013-12-09 12:15:10

Why doesn't QGraphicView work correctly?

Form constructor:

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);


    scene = new QGraphicsScene;
    draw();
}

Draw function:
void Widget::draw()
{

    ui->graphicsView->setScene(scene);
    scene->clear();
    scene->addRect(startX,carcassStartY,
                       maxX*scale,carcassMaxY*scale,
                       QPen(Qt::red, 0),QBrush(Qt::red));
}

Where is the draw called from?
void Widget::on_horizontalSlider_sliderMoved(int position)
{
    scale = position;

    draw();
}

The problem is that when the slider is moved (i.e., the scale changes), the starting point x, y changes, which, as it were, is not indicated in the code. But when the figure climbs out of the field, there are no such changes, everything works correctly.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question