User Expandable QPushButton in Qt application

  • Hi. I have a QPushbutton in my application. Is there any way to make QPushButton as user selectable and expandable when the user drag the border of the button.

    Thank you.

  • Qt Champions 2017

    Well, not directly
    But QSizeGrip can be used to make a fast / not so fancy / hack-ish version
    Note, you need to handle deselecting it again and remove the QSizeGrip etc.
    the code is not complete for really using QSizeGrip.

    For a more full version using sizing object , you can peek at this
    It can work for normal widgets too with only slight modification.

    Disclaimer.  Just for fun code. Ugly , incomplete and hackish.
    #include <QSizeGrip>
    #include <QGridLayout>
     QWidget *the_widget_you_scale=ui->pushButton;
        /// BIG FAT NOTE: PushButtons used fixed height so it wont scale in that direction unless u disable it.
        QSizeGrip * sizeGrip = new QSizeGrip(this);
        QGridLayout * layout = new QGridLayout(the_widget_you_scale);
        layout->addWidget(sizeGrip, 0,0,1,1,Qt::AlignBottom | Qt::AlignRight);

    alt text

  • @mrjj : Thanks for the reply. It works fine.

  • Qt Champions 2017

    super. the code need a bit more of tweaking but it can work ok.
    I used a message filter to check FocusIn and FocusOut events and added the
    Widget into the "sizer" or removed it from it.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.