Results 1 to 4 of 4

Thread: QDockWidget and QListWidget for widget list (QLable, QTextEdit, ect...)

  1. #1
    Join Date
    Apr 2010
    Location
    Italia
    Posts
    149
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QDockWidget and QListWidget for widget list (QLable, QTextEdit, ect...)

    Hi all, I'm a problem: I would use QDockWidget containing a list of widgets like QTextEdit and QList but I do not know how to do.
    I wrote this code inside the MainWindow:
    Qt Code:
    1. QDockWidget *dock = new QDockWidget(tr("Contenitore"), this);
    2. dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
    3. this->addDockWidget(Qt::LeftDockWidgetArea, dock);
    4. QListWidget *listaWid = new QListWidget(dock);
    To copy to clipboard, switch view to plain text mode 
    As I continue to put in a list widget QLabels and a QTextEdit?

    Thanks for the help

  2. #2
    Join Date
    Apr 2010
    Location
    Italia
    Posts
    149
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDockWidget and QListWidget for widget list (QLable, QTextEdit, ect...)

    I'm wrote
    Qt Code:
    1. QWidget *widCentrale = new QWidget(this);
    2. QTextEdit *textEdit = new QTextEdit();
    3. QVBoxLayout *layout = new QVBoxLayout();
    4. layout->addWidget(textEdit);
    5. widCentrale->setLayout(layout);
    6. this->setCentralWidget(widCentrale);
    7.  
    8. QDockWidget *dock = new QDockWidget(tr("Contenitore"), this);
    9. dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
    10. this->addDockWidget(Qt::LeftDockWidgetArea, dock);
    11. QVBoxLayout *layoutDockWid = new QVBoxLayout();
    12. QLabel *labelDockWid = new QLabel(tr("Una label"));
    13. layoutDockWid->addWidget(labelDockWid);
    14. QTextEdit *textEditDockWid = new QTextEdit();
    15. layoutDockWid->addWidget(textEditDockWid);
    16. dock->setLayout(layoutDockWid);
    To copy to clipboard, switch view to plain text mode 
    What is missing in the code to display layoutDockWid and then into the column labelDockWid and textEditDockWid ?

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QDockWidget and QListWidget for widget list (QLable, QTextEdit, ect...)

    You will be seeing warnings about setting a layout on a widget that already has one.

    You set the content of a QDockWidget as a single widget using QDockWidget::setWidget(). You need to wrap your QDockWidget content in a QWidget with its layout and then set that on the dock widget.

  4. #4
    Join Date
    Apr 2010
    Location
    Italia
    Posts
    149
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDockWidget and QListWidget for widget list (QLable, QTextEdit, ect...)

    Thanks ChrisW67 for your advice I solved it:
    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QtGui/QWidget>
    3. #include <QtGui/QVBoxLayout>
    4. #include <QtGui/QDockWidget>
    5. #include <QtGui/QLabel>
    6. #include <QtGui/QTextEdit>
    7.  
    8.  
    9. MainWindow::MainWindow(QWidget *parent) :
    10. QMainWindow(parent)
    11. {
    12. QWidget *widCentrale = new QWidget(this);
    13. QTextEdit *textEdit = new QTextEdit();
    14. QVBoxLayout *layout = new QVBoxLayout();
    15. layout->addWidget(textEdit);
    16. widCentrale->setLayout(layout);
    17. this->setCentralWidget(widCentrale);
    18.  
    19. QDockWidget *dock = new QDockWidget(tr("Contenitore"), this);
    20. dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
    21. this->addDockWidget(Qt::LeftDockWidgetArea, dock);
    22. dock->setFeatures(QDockWidget::NoDockWidgetFeatures); // thus blocking dock widget area
    23.  
    24. // container QWidget to put QVBoxLayout containing QLabel and QTextEdit
    25. QWidget *widDockWid = new QWidget(dock);
    26. QVBoxLayout *layoutDockWid = new QVBoxLayout();
    27. QLabel *labelDockWid = new QLabel(tr("Una label"));
    28. layoutDockWid->addWidget(labelDockWid);
    29. QTextEdit *textEditDockWid = new QTextEdit();
    30. layoutDockWid->addWidget(textEditDockWid);
    31. widDockWid->setLayout(layoutDockWid);
    32. dock->setWidget(widDockWid);
    33. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 8
    Last Post: 17th May 2011, 14:03
  2. Replies: 8
    Last Post: 21st May 2010, 11:26
  3. Replies: 3
    Last Post: 25th February 2010, 18:52
  4. Replies: 2
    Last Post: 19th February 2010, 12:58
  5. Default size of a QListWidget inside a QDockWidget
    By rakuco in forum Qt Programming
    Replies: 0
    Last Post: 25th July 2007, 08:01

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
  •  
Qt is a trademark of The Qt Company.