QT Qsplitter disable scrollbar on resizing QLabel
-
I have added 2 QScrollArea-> QLabel in QSplitter. And am displaying video on both of them. And by default, both of them have same size..
So, when I increase the size of one QLabel by adjusting QSplitter handle, the video takes new allocated space and scales accordingly. However, if I then decrease the size of QLabel, the video would still show up at previous bigger scale and scrollbars would appear.
I instead want to display video without scrollbars and with whatever scale factor that fits current size.
How this can be achieved ? Many thanks in advance!!!
This is my code for displaying image on QLabelmultiews[0] = ui->QImageLabel_view0;
multiews[1] = ui->QImageLabel_view1;
multiews[image_view]->setPixmap(QPixmap::fromImage(qImg).scaled(multiews[image_view]->width(),multiews[image_view]->height(),Qt::KeepAspectRatio)); -
Hi and welcome to devnet,
Why are you putting your labels in QScrollArea rather than ni the QSplitter directly ?
-
Then you have to modify your QScrollArea settings while dragging. See widgetResizable
-
@SGaist
Thanks a lot for your help.
I tried your suggestion, Now I havevoid Dialog::on_splitter_2_splitterMoved(int pos, int index)
{
ui->scrollArea_2->setWidgetResizable(false);
ui->QImageLabel_view0->resize(ui->scrollArea_2->size());
}And I get desired behaviour only when am dragging splitter. However, scrollbars would again show up after releasing splitter handle.
Could you please help me solve this weird behaviour.
Also, may I know how can add ui->QImageLabel_view0->width() variable to watch while debugging. It may help solve the problem.
-
What are you doing when you release the splitter ?
-
@SGaist
There is no signal for Qsplitter released.
I am just refreshing Qlabel image view as shown above.
The above function gets called when Qtimer timeouts.Update:
I modified splitterMoved function as follows:
void Dialog::on_splitter_2_splitterMoved(int pos, int index)
{
ui->scrollArea_2->setWidgetResizable(false);
ui->QImageLabel_view0->setFixedSize(ui->scrollArea_2->size());
ui->scrollAreaWidgetContents_2->setFixedSize(ui->scrollArea_2->size());
width = multiews[0]->size().width();
}
Now am desired behaviour. The contents of image view would scale properly.
However, scrollbars would still show up as shown below. And the extra space marked in red belongs to ui->scrollAreaWidgetContents_2.May I know how should I update its correctly ?
-
Resize the widget so that it doesn't require the scroll bar anymore.
-
@SGaist
I tried very hard. But, still am not satisfied with the implementation. And now am feeling helpless.
If I set set, fixedsize for QLabel, then scroll bars won't appear if I use zoomout/zoomin.
My question is why QLabel won't shrink back after changing size through Qsplitter. I tried all the combinations of sizepolicy and nothing has worked so far