Results 1 to 3 of 3

Thread: open a second window/widget

  1. #1
    Join Date
    Feb 2006
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default open a second window/widget

    Hi to everybody

    first, I have seen a similar posting which doesn't solve my problems.
    I do my first steps with QT and I tried to combine two examples..

    1. -so I compiled the example "application" .. that's working
    2. - than I addad a new menu... I can see this.. that's ok..
    3. - I treid to open the previewWindow from the example "Windows flags", but this doesn't work..

    void MainWindow::indexEnv()
    {
    previewWindow = new PreviewWindow(this);
    previewWindow->activateWindow();
    previewWindow->show();
    }

    indexEnv is the menu and the code insight should open the new widget... but nothing happens..
    can someone help?
    Thanks in advanced

  2. #2
    Join Date
    Feb 2006
    Location
    Kirovohrad, Ukraine
    Posts
    72
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: open a second window/widget

    Let me guess... If you modified the application example you should have the following:
    Qt Code:
    1. //mainwindow.h
    2. //[SKIP]
    3. class MainWindow : public QMainWindow
    4. {
    5. Q_OBJECT
    6. public:
    7. MainWindow();
    8. //[SKIP]
    9. private slots:
    10. void newFile();
    11. //[SKIP]
    12. void documentWasModified();
    13. void indexEnv(); // (1)
    14. private:
    15. void createActions();
    16. //[SKIP]
    17. QMenu *editMenu;
    18. QMenu *helpMenu;
    19. QMenu *yourOwnMenu; // (3)
    20. //[SKIP]
    21. QAction *aboutAct;
    22. QAction *aboutQtAct;
    23. QAction *showYourOwnMenuAction; // (2)
    24. };
    25.  
    26. //mainwindow.cpp
    27. //[SKIP]
    28. void MainWindow::createActions()
    29. {
    30. //[SKIP]
    31. showYourOwnMenuAction = new QAction(tr("Show Preview Window"), this); // (2)
    32. showYourOwnMenuAction->setStatusTip(tr("Show Preview Window from the <i>Windows flags</i> example"));
    33. connect(showYourOwnMenuAction, SIGNAL(triggered()), this, SLOT(indexEnv())); // (5)
    34. //[SKIP]
    35. }
    36. void MainWindow::createMenus()
    37. {
    38. //[SKIP]
    39. yourOwnMenu = menuBar()->addMenu(tr("&Your Menu")); // (3)
    40. yourOwnMenu->addAction(showYourOwnMenuAction); // (4)
    41. //[SKIP]
    42. }
    To copy to clipboard, switch view to plain text mode 
    To achieve the result you need you should do these steps:
    1. Implement your indexEnv() as a slot, so that you can connect() to it
    2. Create a QAction, which is to be triggered() when the user clicks on the corresponding menu item
    3. Create the menu itself
    4. Make your action available through the menu
    5. connect() the QAction's triggered() signal to your MainWindow's indexEnv() slot

  3. #3
    Join Date
    Feb 2006
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: open a second window/widget

    sorry.. only a short test.. the answer will follow

    Qt Code:
    1. //mainwindow.h
    2. //[SKIP]
    3. class MainWindow : public QMainWindow
    4. {
    5. Q_OBJECT
    6.  
    7. public:
    8. MainWindow();
    9.  
    10. protected:
    11. void closeEvent(QCloseEvent *event);
    12.  
    13. private slots:
    14. // [SKIP]
    15. void about();
    16. void indexEnv(); // first steps
    17. void documentWasModified();
    18.  
    19. private:
    20. void createActions();
    21. //[SKIP]
    22.  
    23. PreviewWindow *previewWindow; // first call of a sub dialog
    24.  
    25. QTextEdit *textEdit;
    26. QString curFile;
    27.  
    28. QMenu *fileMenu;
    29. QMenu *editMenu;
    30. QMenu *indexMenu; // first steps to create an index menu --> my own menu
    31. QMenu *helpMenu;
    32.  
    33.  
    34. QToolBar *fileToolBar;
    35. QToolBar *editToolBar;
    36. //[SKIP]
    37. QAction *aboutQtAct;
    38. QAction *indexEnvAct; // first steps to create an index menu --> Action for my own menu
    39. };
    40.  
    41. // mainwindow.cpp
    42. //[SKIP]
    43. void MainWindow::createActions()
    44. {
    45. //[SKIP]
    46. aboutQtAct = new QAction(tr("About &Qt"), this);
    47. aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
    48. connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
    49.  
    50. indexEnvAct = new QAction(tr("&Index Environment settings"), this); // my own action and menu and so on ...
    51. indexEnvAct->setStatusTip(tr("Opens the index environment setting dialog"));
    52. connect(indexEnvAct, SIGNAL(triggered()), qApp, SLOT(indexEnv()));
    53.  
    54. cutAct->setEnabled(false);
    55. copyAct->setEnabled(false);
    56. connect(textEdit, SIGNAL(copyAvailable(bool)),
    57. cutAct, SLOT(setEnabled(bool)));
    58. connect(textEdit, SIGNAL(copyAvailable(bool)),
    59. copyAct, SLOT(setEnabled(bool)));
    60. }
    61.  
    62. void MainWindow::createMenus()
    63. {
    64. //[SKIP]
    65.  
    66. menuBar()->addSeparator();
    67.  
    68. indexMenu = menuBar()->addMenu(tr("&Index"));
    69. indexMenu->addAction(indexEnvAct);
    70. }
    71.  
    72. void MainWindow::indexEnv() // this here is the last part...
    73. {
    74. previewWindow = new PreviewWindow(this);
    75. previewWindow->activateWindow();
    76. previewWindow->show();
    77. }
    To copy to clipboard, switch view to plain text mode 

    so, now I'm hopping, there is somewhere an error... which I can't find...
    Qt Code:
    1. // previewwindow.h
    2. #ifndef PREVIEWWINDOW_H
    3. #define PREVIEWWINDOW_H
    4.  
    5. #include <QWidget>
    6.  
    7. class QTextEdit;
    8.  
    9. class PreviewWindow : public QWidget
    10. {
    11. Q_OBJECT
    12.  
    13. public:
    14. PreviewWindow(QWidget *parent = 0);
    15.  
    16. // void setWindowFlags(Qt::WindowFlags flags);
    17.  
    18. private:
    19. QTextEdit *textEdit;
    20. QPushButton *closeButton;
    21. };
    22.  
    23. #endif
    24.  
    25. // previewwindow.cpp
    26.  
    27. #include <QtGui>
    28.  
    29. #include "previewwindow.h"
    30.  
    31. PreviewWindow::PreviewWindow(QWidget *parent)
    32. : QWidget(parent)
    33. {
    34. textEdit = new QTextEdit;
    35. textEdit->setReadOnly(true);
    36. textEdit->setLineWrapMode(QTextEdit::NoWrap);
    37.  
    38. closeButton = new QPushButton(tr("&Close"));
    39. connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
    40.  
    41. QVBoxLayout *layout = new QVBoxLayout;
    42. layout->addWidget(textEdit);
    43. layout->addWidget(closeButton);
    44. setLayout(layout);
    45.  
    46. setWindowTitle(tr("Preview"));
    47. }
    To copy to clipboard, switch view to plain text mode 

    Is there an error??
    For me it seems correct... the 5 steps you described above seems for me to realised..

    thanks in advanced

Similar Threads

  1. Replies: 3
    Last Post: 7th October 2015, 19:43
  2. Replies: 3
    Last Post: 25th August 2010, 12:39
  3. QTextBrowser: Cannot open
    By veda in forum Qt Programming
    Replies: 3
    Last Post: 27th December 2007, 12:05
  4. again Open Cascade + Qt 4.2.2 but detailed...
    By Shuchi Agrawal in forum Qt Programming
    Replies: 11
    Last Post: 1st February 2007, 07:03
  5. again Open Cascade + Qt 4.2.2 but detailed...
    By Shuchi Agrawal in forum Qt Programming
    Replies: 1
    Last Post: 18th January 2007, 06:50

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.