QLabel snap to ScrollBar
-
Good afternoon. I have a QLabel. I asked a QLabel the picture:
border-image: url(:/Images/Images/map Main.png) 0 0 0 0 stretch stretch;
With these functions I change the size of QLabel:
void MainWindow::on_test Button 1_clicked() { qDebug()<<ui->label Map->width()<<ui->label Map->height(); ui->label Map->setFixedHeight(ui->label Map->height()*2); ui->label Map->setFixedWidth(ui->label Map->width()*2); } void MainWindow::on_test Button 2_clicked() { qDebug()<<ui->label Map->width()<<ui->label Map->height(); ui->label Map->setFixedHeight(ui->label Map->height()/2); ui->label Map->setFixedWidth(ui->label Map->width()/2); }
QLabel how to bind the ScrollBar to be at increased QLabel to change the zoomed area using ScrollBar. Or maybe it can be achieved in another way? In the future, you will need to make buttons on top of QLabel.Maybe you should use QML for this?
-
Hi
You could do as in
https://doc.qt.io/qt-5/qtwidgets-widgets-imageviewer-example.html
and use a ScrollArea with the label inside.
However, this is for normal scrolling when the image is bigger than area where its
displayed.
It sounds a bit like you have some other sort of zoom in mind ? -
@Mikeeeeee
well its constructor is
ImageViewer();
so it doesn't take a parent. you change that so it can be imbedded into what you like. -
@Mikeeeeee
hi
yes you can make setImage public -
@Mikeeeeee
You cannot put whole viewer into a Label.
However, you can use myImageViewer instead of
ui->labelMap -
@Mikeeeeee
well do you have ui->labelMap in layout ?
then just insert myImageViewer into that. -
@Mikeeeeee
but is it a layout? -
@Mikeeeeee said in QLabel snap to ScrollBar:
ui->gridLayout_2
ok then do
ui->gridLayout_2->addWidget(myImageViewer);
You can delete the label if u wish. -
@Mikeeeeee
Its not a configure option. Its new code :)
You can override (add) wheelEvent ( QWheelEvent * event ) to the
ImageViewer class and change the size of the inner QLabel *imageLabel;
to create a zoom in effect.
Or create your on drawing function like here
https://stackoverflow.com/questions/6650219/zooming-function-on-a-qwidget