PDA

View Full Version : Resizeable QTextEdit within a layout



arturoman
25th May 2012, 14:35
I would like to mimic a construct that is seen on some web pages, where a text edit area has it's own resize grip in the corner. Even though it is in a layout, the resizing of that single widget forces the entire area to be layed out again based on the new size of the widget.

Has anyone seen this done of have an idea of how to do it?

Thanks!

Spitfire
28th May 2012, 16:19
Simples:
Just stick the text edit in a layout and on resize (grab and drag) change its fixed size.
This will force everything else in the layout to realign:



MainWindow::MainWindow( QWidget* p )
: QMainWindow( p )
{
QGridLayout* lay = new QGridLayout;

QLabel* l = NULL;

l = new QLabel( "test1" );
l->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
l->setStyleSheet( "background: red;" );
lay->addWidget( l, 0, 0 );

l = new QLabel( "test2" );
l->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
l->setStyleSheet( "background: blue;" );
lay->addWidget( l, 0, 2 );

l = new QLabel( "test3" );
l->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
l->setStyleSheet( "background: green;" );
lay->addWidget( l, 2, 0 );

l = new QLabel( "test4" );
l->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
l->setStyleSheet( "background: yellow;" );
lay->addWidget( l, 2, 2 );

te = new QTextEdit();
lay->addWidget( te, 1, 1 );

QWidget* w = new QWidget( this );
w->setLayout( lay );

this->setCentralWidget( w );
}

void MainWindow::mouseMoveEvent( QMouseEvent* e )
{
QPoint p = te->mapFromParent( e->pos() );
this->te->setFixedSize( QSize( p.x(), p.y() ) );
}

Click LMB anythwere on the grey background and holding it move your mouse.