Results 1 to 9 of 9

Thread: Help with Docked Widget!

  1. #1
    Join Date
    Mar 2007
    Posts
    31
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Help with Docked Widget!

    Hi everybody,
    If I make a Widget in QtDesigner, how can I put it into a MainWindow, like a Docked Widget ?
    Suppose the Widget has other components like Buttons, lineEdits.

    I have read and tried using the QDockWidget with simple samples, adding a textedit, a lineEdit, but I cant do what I want, using a widget previously made in a separate class.

    Thanks and sorry, my english writing is not the best.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Help with Docked Widget!

    So maybe first clearly state what you want and then we'll try to help you. Do you actually want to use a dock widget or is it just an example of some behaviour you want?

  3. #3
    Join Date
    Mar 2007
    Posts
    31
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Help with Docked Widget!

    Thanks for your answer wysota.
    Well, I want to make an application with a textedit and a docket widget to the right side of the Window, the docked will contain a widget with some buttons, and the user will be able to hide, move, and close the docket.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Help with Docked Widget!

    I suggest you implement the two widgets (main window and the contents of the dock) in Designer and them create a dock widget in code and attach it to your main window.

  5. The following user says thank you to wysota for this useful post:

    drake1983 (22nd May 2007)

  6. #5
    Join Date
    May 2007
    Posts
    301
    Thanks
    46
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Help with Docked Widget!

    Hi,

    I use a few docked widgets in my MDI application. This is the code I wrote to do a listbox dock widget and dock it at the bottom of the main window :

    Qt Code:
    1. m_plistWidget = new QCustomListWidget;
    2. QDockWidget* dockwidget = new QDockWidget( tr("Information"), this);
    3. dockwidget->setWidget(m_plistWidget);
    4. dockwidget->setAllowedAreas(Qt::BottomDockWidgetArea | Qt::TopDockWidgetArea);
    5. this->addDockWidget(Qt::BottomDockWidgetArea, dockwidget);
    To copy to clipboard, switch view to plain text mode 

    QCustomListWidget is a widget I did that is derived from QListWidget but has buttons as well.

    Regards,
    Steve

  7. The following user says thank you to steg90 for this useful post:

    drake1983 (22nd May 2007)

  8. #6
    Join Date
    Mar 2007
    Posts
    31
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Help with Docked Widget!

    Thanks for your answers wysota and Steve.

    I made the MainWindow and the other Widget using Qt Desginer.
    Now, I have MainWindow.ui and Editor.ui.

    The MainWindow have a Menu, and it will contain a dock widget with the editor widget.

    This the MainWindow.h code:

    Qt Code:
    1. #include <QMainWindow>
    2. #include <QDockWidget>
    3. #include "ui_MainWindow.h"
    4. #include "editor.h"
    5.  
    6. class MainWindow : public QMainWindow, private Ui::MainWindow
    7. {
    8. Q_OBJECT
    9. public:
    10. QDockWidget* dock; // the dock that will contain the editor widget
    11. Editor* editor; //the widget with the textedit
    12. MainWindow(QWidget* parent = 0, Qt::WFlags fl = 0 );
    13. ~MainWindow();
    14. public slots:
    15.  
    16.  
    17. };
    To copy to clipboard, switch view to plain text mode 

    And this is the MainWindow.cpp


    Qt Code:
    1. #include "mainwindow.h"
    2.  
    3. MainWindow::MainWindow(QWidget* parent, Qt::WFlags fl)
    4. : QMainWindow( parent, fl ), Ui::MainWindow()
    5. {
    6. setupUi(this);
    7. dock = new QDockWidget(tr("Editor"),this);
    8. editor = new Editor(dock);
    9. dock->setWidget(editor);
    10. addDockWidget(Qt::RightDockWidgetArea, dock);
    11. }
    To copy to clipboard, switch view to plain text mode 

    This the code of the Editor, may be will be useful.
    Qt Code:
    1. #include <QWidget>
    2. #include "ui_editor.h"
    3. class Editor : public QWidget, private Ui::Form
    4. {
    5. Q_OBJECT
    6. public:
    7. Editor(QWidget* parent = 0, Qt::WFlags fl = 0 );
    8. ~Editor();
    9. public slots:
    10. };
    To copy to clipboard, switch view to plain text mode 

    Editor.cpp

    Qt Code:
    1. #include "editor.h"
    2.  
    3. Editor::Editor(QWidget* parent, Qt::WFlags fl)
    4. : QWidget( parent, fl ), Ui::Form()
    5. {
    6. setupUi(this);
    7. }
    To copy to clipboard, switch view to plain text mode 

    When I compile the project it works fine, without errors, but the MainWindow doesn't have the docked widget inside. What I'm doing wrong?
    I only got the MainWindow with the Menu. The dock widget doesn't exist.

    thanks!

  9. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Help with Docked Widget!

    You might need to call show() on the dock widget, although I'm not sure of that. I don't remember doing that with my dock widgets.

  10. #8
    Join Date
    Mar 2007
    Posts
    31
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Help with Docked Widget!

    Thanks, I tried with that, but the dock doesn't show it.

  11. #9
    Join Date
    Jun 2007
    Posts
    19
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Help with Docked Widget!

    Quote Originally Posted by drake1983 View Post
    And this is the MainWindow.cpp


    Qt Code:
    1. #include "mainwindow.h"
    2.  
    3. MainWindow::MainWindow(QWidget* parent, Qt::WFlags fl)
    4. : QMainWindow( parent, fl ), Ui::MainWindow()
    5. {
    6. setupUi(this);
    7. dock = new QDockWidget(tr("Editor"),this);
    8. editor = new Editor(dock);
    9. dock->setWidget(editor);
    10. addDockWidget(Qt::RightDockWidgetArea, dock);
    11. }
    To copy to clipboard, switch view to plain text mode 
    I use something more like the following, and it works just fine. I even pass the dock pointer thru plugins and it works great. Mostly, I don't use "this" anywhere.

    Qt Code:
    1. #include "mainwindow.h"
    2.  
    3. MainWindow::MainWindow(QWidget* parent, Qt::WFlags fl)
    4. : QMainWindow( parent, fl )
    5. {
    6. setupUi(this);
    7. dock = new QDockWidget(tr("Editor"));
    8. editor = new Editor();
    9. dock->setWidget(editor);
    10. addDockWidget(Qt::RightDockWidgetArea, dock);
    11. }
    To copy to clipboard, switch view to plain text mode 

    And then the MainWindow.h looks more like :

    Qt Code:
    1. class MainWindow : public QMainWindow, public Ui::MainWindow
    To copy to clipboard, switch view to plain text mode 

    Note that Ui::MainWindow is public.

Similar Threads

  1. Pin/Unpin Dock Widget
    By charlesD in forum Newbie
    Replies: 1
    Last Post: 21st June 2006, 06:57
  2. [Qt 4.1.0] Split a widget on demand
    By Townk in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2006, 14:16

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.