Results 1 to 9 of 9

Thread: Help with multiple forms...!

  1. #1
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Help with multiple forms...!

    Hello all, I am completely new to this forum and quite new to QtCeator... I would like to ask some things about having multiple forms. Ok, let's say that we have a very simple program with only a button "Preferences". When you click this button a new Window (and not QMessageBox) is created with his own features etc... I know how to pop-up a MessageBox, but how do I open a whole new Window? The problem seems huge considering that you have to design its own ui and define its own settings.. Can anyone help me on this?
    I give you the files:
    mainwindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5.  
    6. namespace Ui {
    7. class MainWindow;
    8. }
    9.  
    10. class MainWindow : public QMainWindow {
    11. Q_OBJECT
    12. public:
    13. MainWindow(QWidget *parent = 0);
    14. ~MainWindow();
    15.  
    16. protected:
    17. void changeEvent(QEvent *e);
    18.  
    19. private:
    20. Ui::MainWindow *ui;
    21.  
    22. private slots:
    23. void on_pushButton_clicked();
    24. };
    25.  
    26. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent) :
    5. QMainWindow(parent),
    6. ui(new Ui::MainWindow)
    7. {
    8. ui->setupUi(this);
    9. }
    10.  
    11. MainWindow::~MainWindow()
    12. {
    13. delete ui;
    14. }
    15.  
    16. void MainWindow::changeEvent(QEvent *e)
    17. {
    18. QMainWindow::changeEvent(e);
    19. switch (e->type()) {
    20. case QEvent::LanguageChange:
    21. ui->retranslateUi(this);
    22. break;
    23. default:
    24. break;
    25. }
    26. }
    27.  
    28. void MainWindow::on_pushButton_clicked()
    29. {
    30. //Here the other window should open up
    31. }
    To copy to clipboard, switch view to plain text mode 



    main.cpp
    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "mainwindow.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. MainWindow w;
    8. w.show();
    9. return a.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 
    Screenshot of Gui:

    I have to say that I had the idea an other executable to run each time you press the button preferences but this is quite noob I think

  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 multiple forms...!

    Hi,

    please also note our Newbie section. I would suggest you to read the documentation about signal and slot mechanism and have a look at QDialog.

    Lykurg

  3. #3
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Help with multiple forms...!

    Thank you very much for the answer

  4. #4
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Help with multiple forms...!

    Ok, let's see....
    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3. QDialog *dial = new QDialog;
    4. dial->setWindowTitle("Hello world");
    5. dial->show();
    6. }
    To copy to clipboard, switch view to plain text mode 
    How can I edit this QDialog? Add buttons, labels, etc..?

  5. #5
    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 multiple forms...!

    Quote Originally Posted by hakermania View Post
    How can I edit this QDialog? Add buttons, labels, etc..?
    Like you do with any other QMainWindow or QWidget (which is the base for all other widgets.). And be aware that you delete the pointer somewhere.

  6. The following user says thank you to Lykurg for this useful post:

    hakermania (18th July 2010)

  7. #6
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Help with multiple forms...!

    You add just like in any other QWidgets

    And don't forget to pas the MainWindow as a parent for your QDialog:
    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3. QDialog *dial = new QDialog(this);
    4. dial->setWindowTitle("Hello world");
    5. dial->show();
    6. }
    To copy to clipboard, switch view to plain text mode 

  8. The following user says thank you to Zlatomir for this useful post:

    hakermania (18th July 2010)

  9. #7
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Help with multiple forms...!

    Ok thx for any help.....

  10. #8
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Help with multiple forms...!

    ""You add just like in any other QWidgets""
    And how do I exactly add these in "any other Widgets"???

  11. #9
    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 multiple forms...!

    please read the documentation or any book about Qt! Start the documentation on how to use layouts!

Similar Threads

  1. Multiple Forms Handling
    By eva2002 in forum Qt Programming
    Replies: 5
    Last Post: 11th November 2010, 06:24
  2. tackling multiple forms object
    By eva2002 in forum Qt Programming
    Replies: 3
    Last Post: 28th January 2010, 01:36
  3. Multiple Forms and vertical layout in forms
    By eva2002 in forum Qt Programming
    Replies: 0
    Last Post: 13th January 2010, 05:05
  4. Handling multiple forms
    By msmihai in forum Qt Programming
    Replies: 4
    Last Post: 6th December 2008, 13:41
  5. PyQt - Mapping multiple forms to a database
    By peterjb31 in forum Qt Programming
    Replies: 4
    Last Post: 2nd May 2008, 21:31

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.