Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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.


  • Lifetime Qt Champion

    Hi
    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
    http://www.davidwdrell.net/wordpress/?page_id=46
    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.
        the_widget_you_scale->setWindowFlags(Qt::SubWindow);
        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.


  • Lifetime Qt Champion

    @Shahina
    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