Important: Please read the Qt Code of Conduct -

Adding a QSizeGrip to the corner of a QLabel

  • Hi there,

    I'm attempting to produce a widget that consists of a text display that can be resized by the user grabbing the lower right corner. So far I've been able to generate this:

    ! label)!

    I've applied a read background to the layout to make it more obvious what's going on. I've used the following code to generate this:

    @ m_sizeGrip = new QSizeGrip( this );
    m_layout = new QHBoxLayout( this );
    m_label = new QLabel( this );

    m_layout->setContentsMargins( QMargins() );
    m_layout->setSpacing( 0 );
    m_layout->addWidget( m_label );
    m_layout->addWidget( m_sizeGrip, 0, Qt::AlignBottom | Qt::AlignRight );

    setWindowFlags( Qt::SubWindow );@

    Basically, it's a horizontal layout with the label and grip added to it, which is then installed on a QWidget. My problem is that I'd like the grip to be on the lower right corner of the label, rather than the parent widget. I'd also like to make it invisible while keeping it enabled.

    Or perhaps I'm going about this the wrong way. My ultimate goal is to have a textual display widget that can be resized by the user either horizontally or vertically, but doesn't have a visible grip that would obscure the text. Am I already on the right track with the code above, or is there a better way to achieve this?

  • Hi!

    If you like easy and lazy solutions:
    put a QLablel inside the QDialog (instead of your QWidget) and enable the SizeGrip (QDialog has built-in sizeGripEnabled property).

    I think that's the easiest way.

    Hope that helps,

Log in to reply