Results 1 to 9 of 9

Thread: QT Layout problem

  1. #1
    Join Date
    Jun 2008
    Posts
    32
    Qt products
    Qt4

    Default QT Layout problem

    I want to add a textedit widget to my window. It has a "QHBoxLayout" layout.
    I'm tryin to add this textedit but I cannot. I think, it places the textedit under the treewidget.
    I don't understand why.
    Can u help me pls?
    Here is my code:
    Qt Code:
    1. glWidget = new GLWidget;
    2. tree = new QTreeWidget;
    3. tree->setHeaderLabel("Items");
    4. qtItem = new QTreeWidgetItem(tree);
    5. qtItem->setText(0, tr("QtLogo"));
    6. QWidget *tmpw = new QWidget();
    7. QTextEdit *cmd = new QTextEdit(tmpw);
    8. QHBoxLayout *mainLayout = new QHBoxLayout;
    9. mainLayout->addWidget(glWidget);
    10. mainLayout->addWidget(tree);
    11. mainLayout->addWidget(tmpw);
    To copy to clipboard, switch view to plain text mode 

    Edit: I'm sorry I posted it twice mistakely.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QT Layout problem

    did u set the layout to the main widget ?
    like this->setLayout(mainLayout); ??

  3. #3
    Join Date
    Jun 2008
    Posts
    32
    Qt products
    Qt4

    Default Re: QT Layout problem

    yes i did...

  4. #4
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QT Layout problem

    What are you doing this for?:

    Qt Code:
    1. QWidget *tmpw = new QWidget();
    2. QTextEdit *cmd = new QTextEdit(tmpw);
    3. ...
    4. mainLayout->addWidget(tmpw);
    To copy to clipboard, switch view to plain text mode 

    why not like this:
    Qt Code:
    1. mainLayout->addWidget(cmd);
    To copy to clipboard, switch view to plain text mode 
    I'm a rebel in the S.D.G.

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QT Layout problem

    You add 'tmpw' to 'mainLayout' but 'tmpw' itself doesn't have any layout installed even if it has one child, namely 'cmd'. But what's the point of 'tmpw' anyway if it only contains that QTextEdit?
    J-P Nurmi

  6. #6
    Join Date
    Jun 2008
    Posts
    32
    Qt products
    Qt4

    Default Re: QT Layout problem

    Quote Originally Posted by lyuts View Post
    What are you doing this for?:

    Qt Code:
    1. QWidget *tmpw = new QWidget();
    2. QTextEdit *cmd = new QTextEdit(tmpw);
    3. ...
    4. mainLayout->addWidget(tmpw);
    To copy to clipboard, switch view to plain text mode 

    why not like this:
    Qt Code:
    1. mainLayout->addWidget(cmd);
    To copy to clipboard, switch view to plain text mode 
    cuz QTextEdit is not a qWidgetItem

  7. #7
    Join Date
    Jun 2008
    Posts
    32
    Qt products
    Qt4

    Default Re: QT Layout problem

    Quote Originally Posted by jpn View Post
    You add 'tmpw' to 'mainLayout' but 'tmpw' itself doesn't have any layout installed even if it has one child, namely 'cmd'. But what's the point of 'tmpw' anyway if it only contains that QTextEdit?
    cuz I couldn't add tmpw without putting it into a widget

  8. #8
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QT Layout problem

    Quote Originally Posted by bod View Post
    cuz QTextEdit is not a qWidgetItem
    1) QHBoxLayout's method addWidget accepts QWidget...
    2)
    QTextEdit inherits QAbstractScrollArea
    QAbstractScrollArea inherits QFrame
    QFrame inherits QWidget

    => QTextEdit inherits QWidget

    I have the same question again. Why not just
    Qt Code:
    1. mainLayout->addWidget(cmd);
    To copy to clipboard, switch view to plain text mode 
    ???
    I'm a rebel in the S.D.G.

  9. #9
    Join Date
    Jun 2008
    Posts
    32
    Qt products
    Qt4

    Default Re: QT Layout problem

    It worked just now. I don't know why it did not compile when i first tried it.

Similar Threads

  1. QT Layout problem
    By bod in forum Qt Programming
    Replies: 1
    Last Post: 1st July 2008, 13:29
  2. Layout Problem
    By sabonis in forum Qt Tools
    Replies: 4
    Last Post: 3rd March 2008, 20:57
  3. problem with Tool button n Layout
    By arjunasd in forum Qt Tools
    Replies: 11
    Last Post: 24th July 2007, 21:14
  4. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  5. Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 4
    Last Post: 19th April 2006, 11:08

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.