Question

I've got stuck in this problem and try almost all other similar problems, but none of them doesn't work, any help appreciate it.

Problem, i have a custom widget, in my custom widget i have a QScrollArea and inside QScrollArea i have a Qlabal that inherit from a subclass from Qlable.

Now when i load image, because setscalecontent is true, the image is fitted to lable, but i have a button for changing image to normal size or first size, and for it i use from adjustsize, the image returns to first size but the scrollbars are not loaded, also widgetresizable is true,

setupui for my widget:

   void setupUi(QWidget *widget_img_2d)
{
    if (widget_img_2d->objectName().isEmpty())
        widget_img_2d->setObjectName(QString::fromUtf8("widget_img_2d"));
    widget_img_2d->resize(569, 379);
    gridLayout = new QGridLayout(widget_img_2d);
    gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
    scrollArea = new QScrollArea(widget_img_2d);
    scrollArea->setObjectName(QString::fromUtf8("scrollArea"));
    scrollArea->setWidgetResizable(true);
    scrollArea->setAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter);
    scrollAreaWidgetContents = new QWidget();
    scrollAreaWidgetContents->setObjectName(QString::fromUtf8("scrollAreaWidgetContents"));
    scrollAreaWidgetContents->setGeometry(QRect(0, 0, 549, 359));
    QSizePolicy sizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    sizePolicy.setHorizontalStretch(0);
    sizePolicy.setVerticalStretch(0);
    sizePolicy.setHeightForWidth(scrollAreaWidgetContents->sizePolicy().hasHeightForWidth());
    scrollAreaWidgetContents->setSizePolicy(sizePolicy);
    gridLayout_2 = new QGridLayout(scrollAreaWidgetContents);
    gridLayout_2->setObjectName(QString::fromUtf8("gridLayout_2"));
    lbl_img = new my_qlable(scrollAreaWidgetContents);
    lbl_img->setObjectName(QString::fromUtf8("lbl_img"));
    sizePolicy.setHeightForWidth(lbl_img->sizePolicy().hasHeightForWidth());
    lbl_img->setSizePolicy(sizePolicy);
    lbl_img->setAutoFillBackground(false);
    lbl_img->setScaledContents(true);

    gridLayout_2->addWidget(lbl_img, 0, 0, 1, 1);

    scrollArea->setWidget(scrollAreaWidgetContents);

    gridLayout->addWidget(scrollArea, 0, 0, 1, 1);


    retranslateUi(widget_img_2d);

    QMetaObject::connectSlotsByName(widget_img_2d);
} // setupUi
Was it helpful?

Solution

I found a way to solve this problem. by changing sizepolicy in each state, i got what i want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top