That's a nice link, but I still have problems:
Scrollbars don't appear when the image is larger than the viewport.
Switching back to fit mode doesn't work.
The image's aspect ratio isn't retained in fit mode.
It uses a smooth scaling algorithm which takes a ridiculously long time to complete.
Here is some relavent code:
void MainWindow::fitButton(bool on) // note that fitButton is checkable
{
ui->imageScrollArea->setWidgetResizable(on);
ui->actualSizeButton->setDisabled(on);
ui->zoomSlider->setDisabled(on);
ui->zoomLabel->setDisabled(on);
}
void MainWindow::actualSizeButton()
{
ui->zoomSlider->setValue(100);
}
void MainWindow::zoomSlider(int value)
{
QSize size
= ui
->imageLabel
->pixmap
()->size
();
size.setWidth((size.width() * value) / 100);
size.setHeight((size.height() * value) / 100);
ui->imageLabel->resize(size);
}
void MainWindow::fitButton(bool on) // note that fitButton is checkable
{
ui->imageScrollArea->setWidgetResizable(on);
ui->actualSizeButton->setDisabled(on);
ui->zoomSlider->setDisabled(on);
ui->zoomLabel->setDisabled(on);
}
void MainWindow::actualSizeButton()
{
ui->zoomSlider->setValue(100);
}
void MainWindow::zoomSlider(int value)
{
QSize size = ui->imageLabel->pixmap()->size();
size.setWidth((size.width() * value) / 100);
size.setHeight((size.height() * value) / 100);
ui->imageLabel->resize(size);
}
To copy to clipboard, switch view to plain text mode
Bookmarks