Important: Please read the Qt Code of Conduct -

Dynamically grow a widget into negative values.

  • Hello the following code will do a pretty good job at growing a widget dynamically; that has been placed in a QScrolArea object, using setMinimumSize(). However this is probably not the best solution to do this and isn't a solution at all to grow the widget in a negative fashion thus increasing space in my upper and left regions.

    to Give more information when I drag a widget in a parent widget that is housed in the QScroll Area, I want my parent widget geometry to grow in a negative direction (top and left) and have my QScrollArea increase in negative amounts.

       QPoint TL = aCustomWidget->pos();
       int widthCord = TL.x() + aCustomWidget->width();
       int heightCord = TL.y() + aCustomWidget->height();
       QPoint BR(widthCord, heightCord);
       if(BR.x() > this->width()-10 || BR.y() > this->height()-10) 
           QRect oldGeo = this->geometry();
           this->setGeometry(oldGeo.x(), oldGeo.y(), oldGeo.width()+5, oldGeo.height()+5); 
           int sizerX = abs(this->x())+this->width();
           int sizerY = abs(this->y())+this->height();
           setMinimumSize(sizerX, sizerY)

Log in to reply