调整大小和QScrollArea

时间:2015-07-20 01:42:48

标签: c++ qt

我想让我的框架“ImageLoader”根据图像的大小调整大小。如果可能的话,我希望它能够调整窗口的大小。如果图像大于屏幕或者用户缩小了框架,我希望它添加滚动条。我尝试添加一个Qscrollarea并设置小部件,但无论如何都要添加滚动条。如何让qt按我的意愿行事?

ImageLoader::ImageLoader(QWidget *parent, QImage &image) : GLWindow(parent)
{
    mCentralWidget = new QWidget(this);
    setCentralWidget(mCentralWidget);

    QHBoxLayout *mainLayout = new QHBoxLayout;
    mainLayout->setMargin(0);
    mCentralWidget->setLayout(mainLayout);

    ImageBounds* bounds = new ImageBounds(this);
    mainLayout->addWidget(bounds);

    mCanvas = new Canvas(this);
    mCanvas->setMinimumSize(image.width(), image.height());
    QScrollArea* scrollArea = new QScrollArea;
    scrollArea->setWidget(mCanvas);
    mainLayout->addWidget(scrollArea);

    mSpnRows = 1;
    mSpnColumns = 1;
    mSpnX = 0;
    mSpnY = 0;

    connect(bounds->spnRows, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &ImageLoader::setSpnRows);
    connect(bounds->spnColumns, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &ImageLoader::setSpnColumns);
    connect(bounds->spnXsep, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &ImageLoader::setSpnX);
    connect(bounds->spnYsep, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &ImageLoader::setSpnY);

    QImage checkers = createCheckers();
    mCheckers = new Sprite(checkers, width(), height());

    mSpr = new Sprite(image);
    mGrid = new Grid(mSpr->width(), mSpr->height(), 1, 1, 0, 0);
} 

0 个答案:

没有答案