Results 1 to 7 of 7

Thread: Help with QDockWidget

  1. #1
    Join Date
    Mar 2010
    Location
    Sunny South Florida
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Help with QDockWidget

    I'm sure this question has been answered somewhere in this forum but I can't seem to find exactly what I need so I'm going to ask you guys for a little help. I'm trying to build an app using the QDockWidget. My problem is getting things working properly. Let me start by asking, is it proper protocol to design my "QDockWidget" in designer or am I supposed to to design a std widget in designer and sub-class it as a QDockWidget? I've been trying to design my QDockWidget and then use it directly. (see code below). It just seems I'm making things more complicated than they should be in this IDE.

    Pls note that I deleted some of what I thought to be non-essential code for brevity. If you need everything just ping me on skype or gmail and I'll send it over.

    Thanks for you help!!!

    Chris L.

    Slick Systems Development
    Phone: 561-253-3755
    Fax: 561-253-3754
    Toll Free: 1-800-513-4525
    Email: qtinfo@slicksys.net
    Website: http://www.slicksys.net



    ---------- Begin Code ------------------

    ----- main.cpp -----
    #include "mainwindow.h"

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    return a.exec();
    }

    ------------ mainwindow.cpp -----------

    #include "mainwindow.h"

    MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
    {
    setWindowTitle("s");
    ui->setupUi(this);
    textEdit = new QTextEdit;
    setCentralWidget(textEdit);
    createDockWindows();
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::createDockWindows()
    {

    cbuilder = new CriteriaBuilder(this);
    cbuilder->setBaseSize(QSize(140,600));
    cbuilder->setAllowedAreas(Qt::RightDockWidgetArea);
    addDockWidget(Qt::RightDockWidgetArea,cbuilder);

    /*
    summ=new Summary(this);
    summ->setBaseSize(QSize(140,600));
    summ->setAllowedAreas(Qt::LeftDockWidgetArea);
    addDockWidget(Qt::LeftDockWidgetArea,summ);
    */
    return;
    }

    void MainWindow::changeEvent(QEvent *e)
    {
    QMainWindow::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
    ui->retranslateUi(this);
    break;
    default:
    break;
    }
    }

    ------------ criteriabuilder.cpp ------------
    #include "criteriabuilder.h"

    CriteriaBuilder::CriteriaBuilder(QWidget *parent) : QDockWidget(parent), ui(new Ui::CriteriaBuilder)
    {
    ui->setupUi(this);
    }

    CriteriaBuilder::~CriteriaBuilder()
    {
    delete ui;
    }

    void CriteriaBuilder::changeEvent(QEvent *e)
    {
    QDockWidget::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
    ui->retranslateUi(this);
    break;
    default:
    break;
    }
    }


    --------

    #ifndef CRITERIABUILDER_H
    #define CRITERIABUILDER_H

    #include "ui_criteriaBuilder.h"

    namespace Ui {
    class CriteriaBuilder;
    }

    class CriteriaBuilder : public QDockWidget
    {
    Q_OBJECT

    public:

    CriteriaBuilder(QWidget *parent = 0);
    ~CriteriaBuilder();

    protected:
    void changeEvent(QEvent *e);

    private:
    Ui::CriteriaBuilder *ui;
    };


    #endif // CRITERIABUILDER_H



    ---------------- mainwindow.h-------------

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    #include <QtGui/QApplication>
    #include <QDockWidget>
    #include <QtCore/QVariant>
    #include <QtGui/QAction>
    #include <QtGui/QApplication>
    #include <QtGui/QButtonGroup>
    #include <QtGui/QCheckBox>
    #include <QtGui/QComboBox>
    #include <QtGui/QDockWidget>
    #include <QtGui/QFrame>
    #include <QtGui/QGridLayout>
    #include <QtGui/QHeaderView>
    #include <QtGui/QLabel>
    #include <QtGui/QLineEdit>
    #include <QtGui/QSlider>
    #include <QtGui/QSpacerItem>
    #include <QtGui/QTextEdit>
    #include <QtGui/QWidget>

    #include "ui_mainwindow.h"
    #include "criteriabuilder.h"
    #include "summary.h"


    //QT_BEGIN_NAMESPACE
    //class QTextEdit;
    //QT_END_NAMESPACE

    namespace Ui
    {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT
    public:
    MainWindow(QWidget *parent = 0);
    ~MainWindow();

    protected:
    void changeEvent(QEvent *e);

    private:
    void createDockWindows();

    Ui::MainWindow *ui;
    CriteriaBuilder *cbuilder;
    Summary *summ;
    QTextEdit *textEdit;
    QMenu *fileMenu;
    QMenu *editMenu;
    QMenu *viewMenu;
    QMenu *helpMenu;
    QToolBar *fileToolBar;
    QToolBar *editToolBar;
    QAction *newLetterAct;
    QAction *saveAct;
    QAction *printAct;
    QAction *undoAct;
    QAction *aboutAct;
    QAction *aboutQtAct;
    QAction *quitAct;


    };

    #endif // MAINWINDOW_H


    --------------------------------------

    #ifndef UI_CRITERIABUILDER_H
    #define UI_CRITERIABUILDER_H

    #include <QtCore/QVariant>
    #include <QtGui/QAction>
    #include <QtGui/QApplication>
    #include <QtGui/QButtonGroup>
    #include <QtGui/QCheckBox>
    #include <QtGui/QComboBox>
    #include <QtGui/QDockWidget>
    #include <QtGui/QFrame>
    #include <QtGui/QGridLayout>
    #include <QtGui/QHeaderView>
    #include <QtGui/QLabel>
    #include <QtGui/QLineEdit>
    #include <QtGui/QSlider>
    #include <QtGui/QSpacerItem>
    #include <QtGui/QWidget>

    QT_BEGIN_NAMESPACE

    class Ui_CriteriaBuilder
    {
    public:
    QWidget *dockWidgetContents;
    QGridLayout *gridLayout_9;

    ... deleted code for brevity ...


    void setupUi(QDockWidget *CriteriaBuilder)
    {
    if (CriteriaBuilder->objectName().isEmpty())
    CriteriaBuilder->setObjectName(QString::fromUtf8("CriteriaBuilder" ));

    ... deleted code for brevity ....

    QMetaObject::connectSlotsByName(CriteriaBuilder);
    } // setupUi

    void retranslateUi(QDockWidget *CriteriaBuilder)
    {
    CriteriaBuilder->setWindowTitle(QApplication::translate("CriteriaB uilder", "Option Selection Criteria Builder", 0, QApplication::UnicodeUTF8));
    checkBox_38->setText(QString());
    } // retranslateUi

    };

    namespace Ui {
    class CriteriaBuilder: public Ui_CriteriaBuilder {};
    } // namespace Ui

    QT_END_NAMESPACE

    #endif // UI_CRITERIABUILDER_H

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Help with QDockWidget

    Quote Originally Posted by mindbender View Post
    Let me start by asking, is it proper protocol to design my "QDockWidget" in designer or am I supposed to to design a std widget in designer and sub-class it as a QDockWidget? I've been trying to design my QDockWidget and then use it directly. (see code below). It just seems I'm making things more complicated than they should be in this IDE.
    It doesn't matter which way you use. You can use your main window ui and add the dock widget right there, or you can make a own class "dock widget" at the designer and add it the the main window by calling addDockWidget().
    I personally like the last approach since it separates your code nicely. All the code belonging to the dock widget is bundled at one place.

    (And we have nice [CODE] tags at this forum)

  3. #3
    Join Date
    Mar 2010
    Location
    Sunny South Florida
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Help with QDockWidget

    My apologies, I didn't think about the code tags. Is it possible you or someone could post a simple example of what the code would look like
    with a qdockwidget created in the designer coded into a main window. I've been fighting it for awhile and I'd like to see what i'm not doing right.

    Thanks again! I'll be sure and use the code tags from now on too. :-)

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Help with QDockWidget

    Just a quick build...
    Attached Files Attached Files

  5. #5
    Join Date
    Mar 2010
    Location
    Sunny South Florida
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Help with QDockWidget

    Thank You Lykurg for your kindness!

  6. #6
    Join Date
    Mar 2010
    Location
    Sunny South Florida
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Help with QDockWidget

    Ah looks like my code was correct. The problem was that I had renamed the "DockWidget.ui" file to "criteriabuilder.ui" without changing the name of the class in QDesigner.
    When I try to do anything with class "CriteriaBuilder" it did a lot of complaining. Once I found the naming issue in the UI file everthing was as you said it should be. I knew
    I was somehow making things overly complicated.

    ...again I appreciate your help.

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Help with QDockWidget

    Quote Originally Posted by mindbender View Post
    ...again I appreciate your help.
    You are welcome! Good you find that error.

Similar Threads

  1. QDockWidget and more
    By Carlsberg in forum Qt Programming
    Replies: 1
    Last Post: 2nd June 2009, 09:47
  2. Alignment of QDockWidget
    By pospiech in forum Qt Programming
    Replies: 2
    Last Post: 4th December 2008, 13:59
  3. QDockwidget
    By peace_comp in forum Qt Programming
    Replies: 3
    Last Post: 30th June 2008, 05:19
  4. QDockWidget
    By fellobo in forum Qt Programming
    Replies: 8
    Last Post: 26th June 2008, 18:52
  5. QDockWidget
    By ToddAtWSU in forum Qt Programming
    Replies: 6
    Last Post: 29th November 2007, 13:37

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.