Results 1 to 2 of 2

Thread: Resizeable QTextEdit within a layout

  1. #1
    Join Date
    May 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Resizeable QTextEdit within a layout

    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!

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Resizeable QTextEdit within a layout

    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:

    Qt Code:
    1. MainWindow::MainWindow( QWidget* p )
    2. : QMainWindow( p )
    3. {
    4.  
    5. QLabel* l = NULL;
    6.  
    7. l = new QLabel( "test1" );
    8. l->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
    9. l->setStyleSheet( "background: red;" );
    10. lay->addWidget( l, 0, 0 );
    11.  
    12. l = new QLabel( "test2" );
    13. l->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
    14. l->setStyleSheet( "background: blue;" );
    15. lay->addWidget( l, 0, 2 );
    16.  
    17. l = new QLabel( "test3" );
    18. l->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
    19. l->setStyleSheet( "background: green;" );
    20. lay->addWidget( l, 2, 0 );
    21.  
    22. l = new QLabel( "test4" );
    23. l->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
    24. l->setStyleSheet( "background: yellow;" );
    25. lay->addWidget( l, 2, 2 );
    26.  
    27. te = new QTextEdit();
    28. lay->addWidget( te, 1, 1 );
    29.  
    30. QWidget* w = new QWidget( this );
    31. w->setLayout( lay );
    32.  
    33. this->setCentralWidget( w );
    34. }
    35.  
    36. void MainWindow::mouseMoveEvent( QMouseEvent* e )
    37. {
    38. QPoint p = te->mapFromParent( e->pos() );
    39. this->te->setFixedSize( QSize( p.x(), p.y() ) );
    40. }
    To copy to clipboard, switch view to plain text mode 
    Click LMB anythwere on the grey background and holding it move your mouse.

Similar Threads

  1. foreach QTextEdit in Layout
    By slc in forum Qt Programming
    Replies: 1
    Last Post: 2nd September 2010, 00:45
  2. Resizeable Dialog/Layout (like Dolphin)
    By kiss-o-matic in forum Qt Programming
    Replies: 2
    Last Post: 20th December 2009, 23:18
  3. Adjust the initial size of a QTextEdit in a layout
    By hecinho in forum Qt Programming
    Replies: 0
    Last Post: 26th November 2009, 15:58
  4. Resizeable main window in Qt Creator?
    By Lendrick in forum Qt Tools
    Replies: 2
    Last Post: 3rd June 2009, 19:57
  5. Is there a resizeable layout
    By seneca in forum Qt Tools
    Replies: 2
    Last Post: 14th January 2006, 20:04

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.