×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    272

    Question How to create stackable windows with ui files?

    I'm trying to make stackable windows with Qt Creator. I have a MainWindow ui file. I'm trying to follow How to create stackable windows in Maemo 5, but here it seems a new window is created from scratch. How can I use an existing MainWindow created with Qt Creator?

    Cheers

  2. #2
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: How to create stackable windows with ui files?

    So copy-pasting the code from wiki to main.cpp didn't work for you?

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    272

    Re: How to create stackable windows with ui files?

    Quote Originally Posted by divanov View Post
    So copy-pasting the code from wiki to main.cpp didn't work for you?
    No, not really as I'm trying to add to an existing project. I also what to use Qt Creator. This is it does when creating a new MainWindow:

    mainwindow.h
    Code:
    namespace Ui {
        class MainWindow;
    }
    
    class MainWindow : public QMainWindow {
        Q_OBJECT
    public:
        MainWindow(QWidget *parent = 0);
        ~MainWindow();
    .
    .
    .
    mainwindow.cpp
    Code:
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    .
    .
    .
    How to stack another QMainWindow created with Qt Creator on top of this?

  4. #4
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: How to create stackable windows with ui files?

    Quote Originally Posted by Sasler View Post
    No, not really as I'm trying to add to an existing project. I also what to use Qt Creator.
    How to stack another QMainWindow created with Qt Creator on top of this?
    I don't get how does it differ, if you use Qt Creator?

  5. #5
    Registered User
    Join Date
    Jan 2010
    Posts
    272

    Re: How to create stackable windows with ui files?

    Quote Originally Posted by divanov View Post
    I don't get how does it differ, if you use Qt Creator?
    I want to use an existing ui file. Maybe I have misunderstood the example in the Wiki or I'm too stupid, but I don't know how to use it with an existing ui file.

  6. #6
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: How to create stackable windows with ui files?

    Quote Originally Posted by Sasler View Post
    I want to use an existing ui file. Maybe I have misunderstood the example in the Wiki or I'm too stupid, but I don't know how to use it with an existing ui file.
    .ui files are created and modified by Qt Designer. You don't use them directly anywhere. You edit
    main.cpp
    mainwindow.cpp
    mainwindow.h
    mainwindow2.cpp
    mainwindow2.h

    Example in the wiki is content of main.cpp.

  7. #7
    Registered User
    Join Date
    Jan 2010
    Posts
    272

    Re: How to create stackable windows with ui files?

    Quote Originally Posted by divanov View Post
    .ui files are created and modified by Qt Designer. You don't use them directly anywhere. You edit
    main.cpp
    mainwindow.cpp
    mainwindow.h
    mainwindow2.cpp
    mainwindow2.h

    Example in the wiki is content of main.cpp.
    OK. I understand that. But let's say I have menu item called "Settings" in the mainwindow. When it's triggered, I want it to open the mainwindow2. How would I do that?

  8. #8
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: How to create stackable windows with ui files?

    It turns out to be a general Qt question: how do I develop an application with two windows.

    The solution is to create and show second window in a slot of QAction's triggered signal.
    http://doc.trolltech.com/4.6/qaction.html#triggered

  9. #9
    Registered User
    Join Date
    Jan 2010
    Posts
    272

    Re: How to create stackable windows with ui files?

    Quote Originally Posted by divanov View Post
    It turns out to be a general Qt question: how do I develop an application with two windows.

    The solution is to create and show second window in a slot of button's clicked signal.
    http://doc.trolltech.com/4.6/qabstra...n.html#clicked
    I am already using dialogs in the project and I know how to do that. Here is what I'm doing:

    mainwindow.h
    Code:
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include "about.h"
    #include "help.h"
    
    namespace Ui {
        class MainWindow;
    }
    
    class MainWindow : public QMainWindow {
        Q_OBJECT
    public:
        MainWindow(QWidget *parent = 0);
        ~MainWindow();
    
    protected:
        void changeEvent(QEvent *e);
    
    private:
        Ui::MainWindow *ui;
        About *aboutDialog;
        Help *helpDialog;
    mainwindow.cpp
    Code:
    void MainWindow::on_actionHelp_triggered()
    {
        helpDialog = new Help;
        helpDialog->exec();
    }
    
    void MainWindow::on_actionAbout_triggered()
    {
        aboutDialog = new About;
        aboutDialog->exec();
    }
    But instead of making a dialog, I want to make stackable windows. How would I do that?

  10. #10
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: How to create stackable windows with ui files?

    It's as simple as combination of the dialog creation code and the code from wiki:
    Code:
    void MainWindow::on_someAction_triggered(bool checked)
    {
        Q_UNUSED(checked);
    
        MainWindow2 *win2 = new MainWindow2(this);
        // this is the only Maemo specific line here
        win2->setAttribute(Qt::WA_Maemo5StackedWindow);
        win2->show();
    }
    Qt comes with examples and some of them has similar code for windows creation. For example there is Maemo5 stackable windows example, which creates windows dynamically.

  11. #11
    Registered User
    Join Date
    Jan 2010
    Posts
    272

    Re: How to create stackable windows with ui files?

    Quote Originally Posted by divanov View Post
    It's as simple as combination of the dialog creation code and the code from wiki:
    Code:
    void MainWindow::on_someAction_triggered(bool checked)
    {
        Q_UNUSED(checked);
    
        MainWindow2 *win2 = new MainWindow2(this);
        // this is the only Maemo specific line here
        win2->setAttribute(Qt::WA_Maemo5StackedWindow);
        win2->show();
    }
    Qt comes with examples and some of them has similar code for windows creation. For example there is Maemo5 stackable windows example, which creates windows dynamically.
    Oh, thanks. Now it works.
    But I didn't even need this line:
    Code:
    win2->setAttribute(Qt::WA_Maemo5StackedWindow)
    All I needed was "(this)".

    Thanks a lot!

  12. #12
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: How to create stackable windows with ui files?

    Quote Originally Posted by Sasler View Post
    But I didn't even need this line:
    Code:
    win2->setAttribute(Qt::WA_Maemo5StackedWindow)
    Are you using Qt 4.5.3?

  13. #13
    Registered User
    Join Date
    Jan 2010
    Posts
    272

    Re: How to create stackable windows with ui files?

    Quote Originally Posted by divanov View Post
    Are you using Qt 4.5.3?
    I'm using whatever comes with Maemo 5 and MADDE. I know that it's not 4.6, but I'm not sure whether it's 4.5 or 4.5.3.

  14. #14
    Registered User
    Join Date
    Jan 2010
    Posts
    272

    Re: How to create stackable windows with ui files?

    Now I got another problem. Since I have to use show instead of exec, how can I trigger a refresh on various objects after the stacked window is closed? Is there some kind of signal/slot I could use?

  15. #15
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: How to create stackable windows with ui files?

    This is not a problem. There is QWidget::closeEvent for this
    http://doc.trolltech.com/4.6/qwidget.html#closeEvent

Similar Threads

  1. How to create multiple files in Symbian
    By arungupta_2jan in forum Symbian Tools & SDKs
    Replies: 4
    Last Post: 2008-04-14, 14:16
  2. linking error
    By dakosurf in forum Symbian
    Replies: 1
    Last Post: 2008-03-27, 22:45
  3. SMIL2MMS: A tool to create and deploy MMS files
    By jimmccurdy in forum General Messaging
    Replies: 3
    Last Post: 2002-10-16, 08:24

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×