Page 2 of 2 FirstFirst 12
Results 21 to 28 of 28

Thread: How to take window from QWorkspace?

  1. #21
    Join Date
    Nov 2012
    Posts
    232
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Platforms
    Windows Android

    Default Re: How to take window from QWorkspace?

    I replace QWorkspace -> QMdiArea

    Qt Code:
    1. //workspace = new QWorkspace;
    2. mdiArea = new QMdiArea;
    3. //setCentralWidget( workspace );
    4. setCentralWidget( mdiArea );
    5.  
    6. createActions();
    7. createMenus();
    8. createToolbars();
    9.  
    10. showScenePanel();
    11. showControlPanel();
    12.  
    13. scenePanel = new ScenePanel;
    14. //scenePanel = qobject_cast<ScenePanel *>((workspace->windowList()).at(0));
    15. scenePanel = qobject_cast<ScenePanel *>((mdiArea->subWindowList()).at(0));
    16. controlPanel = new ControlPanel;
    17. //controlPanel = qobject_cast<ControlPanel *>((workspace->windowList()).at(1));
    18. controlPanel = qobject_cast<ControlPanel *>((mdiArea->subWindowList()).at(1));
    19.  
    20. scenePanel->setWindowIcon(QIcon(":/Icons/Scene.png")); // <---- RED LINE
    21. controlPanel->setWindowIcon(QIcon(":/Icons/Control.png"));
    To copy to clipboard, switch view to plain text mode 

    But the program crashes at run time (on the red line)

  2. #22
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: How to take window from QWorkspace?

    Comment lines #15 and #18 in the above code
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. The following user says thank you to Santosh Reddy for this useful post:

    8Observer8 (23rd August 2013)

  4. #23
    Join Date
    Nov 2012
    Posts
    232
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Platforms
    Windows Android

    Default Re: How to take window from QWorkspace?

    I did it. The program isn't crushed.

    But I see:

    48.png

    My Project:
    Attached Files Attached Files

  5. #24
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: How to take window from QWorkspace?

    Here is corrected code...
    Attached Files Attached Files
    Last edited by Santosh Reddy; 23rd August 2013 at 13:41.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

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

    8Observer8 (23rd August 2013)

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

    Default Re: How to take window from QWorkspace?

    Qt Code:
    1. QList<QMdiSubWindow*> windows = mdi->subWindowList();
    2. windows.at(0)->setWindowIcon(QIcon(":/Icons/Scene.png"));
    3. windows.at(1)->setWindowIcon(QIcon(":/Icons/Control.png"));
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    8Observer8 (23rd August 2013)

  9. #26
    Join Date
    Nov 2012
    Posts
    232
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Platforms
    Windows Android

    Default Re: How to take window from QWorkspace?

    I have ran it with "QWorkspase". It worked normally.

    Quote Originally Posted by wysota View Post
    Qt Code:
    1. QList<QMdiSubWindow*> windows = mdi->subWindowList();
    2. windows.at(0)->setWindowIcon(QIcon(":/Icons/Scene.png"));
    3. windows.at(1)->setWindowIcon(QIcon(":/Icons/Control.png"));
    To copy to clipboard, switch view to plain text mode 
    Thanks! It works.

    But program works illegal.


    Added after 5 minutes:


    How to do that:

    Qt Code:
    1. scenePanel = qobject_cast<ScenePanel *>(windows.at(0));
    2. controlPanel = qobject_cast<ControlPanel *>(windows.at(1));
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by Santosh Reddy View Post
    Here is corrected code...
    Thank you very much


    Added after 40 minutes:


    In addition, instead:

    Qt Code:
    1. scenePanel->resize(500, 500);
    To copy to clipboard, switch view to plain text mode 

    I wrote

    Qt Code:
    1. sceneWindow->resize(500, 500);
    To copy to clipboard, switch view to plain text mode 

    Guys, thanks for help! I am happy
    Last edited by 8Observer8; 23rd August 2013 at 14:30.

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

    Default Re: How to take window from QWorkspace?

    Quote Originally Posted by 8Observer8 View Post
    How to do that:

    Qt Code:
    1. scenePanel = qobject_cast<ScenePanel *>(windows.at(0));
    2. controlPanel = qobject_cast<ControlPanel *>(windows.at(1));
    To copy to clipboard, switch view to plain text mode 
    This won't work because the returned widget is an instance of QMdiSubWindow and not your widget.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    8Observer8 (23rd August 2013)

  12. #28
    Join Date
    Nov 2012
    Posts
    232
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Platforms
    Windows Android

    Default Re: How to take window from QWorkspace?

    Santosh Reddy have corrected:

    mainwindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include "controlpanel.h"
    6. #include "scenepanel.h"
    7.  
    8. class QAction;
    9. class QMdiSubWindow;
    10. class QMdiArea;
    11. class QMenu;
    12.  
    13. class MainWindow : public QMainWindow
    14. {
    15. Q_OBJECT
    16. public:
    17. explicit MainWindow(QWidget *parent = 0);
    18.  
    19. signals:
    20.  
    21. public slots:
    22.  
    23. private:
    24. void createActions();
    25. void createMenus();
    26. void createToolbars();
    27.  
    28. QMdiArea *mdiArea;
    29.  
    30. QAction *sceneAction;
    31. QAction *controlAction;
    32.  
    33. ScenePanel *scenePanel;
    34. ControlPanel *controlPanel;
    35.  
    36. QMdiSubWindow * sceneWindow;
    37. QMdiSubWindow * controlWindow;
    38.  
    39. private slots:
    40. void showScenePanel();
    41. void showControlPanel();
    42. };
    43.  
    44. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QtGui>
    3.  
    4. MainWindow::MainWindow(QWidget *parent) :
    5. QMainWindow(parent)
    6. {
    7. this->setWindowTitle(tr("mdiLine"));
    8. mdiArea = new QMdiArea;
    9. setCentralWidget( mdiArea );
    10.  
    11. createActions();
    12. createMenus();
    13. createToolbars();
    14.  
    15. scenePanel = new ScenePanel;
    16. scenePanel->setWindowIcon(QIcon(":/Icons/Scene.png"));
    17. sceneWindow = mdiArea->addSubWindow(scenePanel);
    18. sceneWindow->resize(500, 500);
    19.  
    20. controlPanel = new ControlPanel;
    21. controlPanel->setWindowIcon(QIcon(":/Icons/Control.png"));
    22. controlWindow = mdiArea->addSubWindow(controlPanel);
    23.  
    24. connect(controlPanel, SIGNAL(drawLine(QVector3D,QVector3D)), scenePanel, SLOT(drawLine(QVector3D,QVector3D)));
    25.  
    26. showScenePanel();
    27. showControlPanel();
    28. }
    29.  
    30. void MainWindow::createActions() {
    31. sceneAction = new QAction( QIcon(":/Icons/Scene.png"), tr("&Scene"), this );
    32. sceneAction->setStatusTip( tr("Scene Panel") );
    33. connect( sceneAction, SIGNAL(triggered()), this, SLOT(showScenePanel()) );
    34.  
    35. controlAction = new QAction( QIcon(":/Icons/Control.png"), tr("&Control"), this );
    36. controlAction->setStatusTip( tr("Control Panel") );
    37. connect( controlAction, SIGNAL(triggered()), this, SLOT(showControlPanel()) );
    38. }
    39.  
    40. void MainWindow::createMenus() {
    41. QMenu *menu;
    42. menu = menuBar()->addMenu( tr("&Panels") );
    43. menu->addAction( sceneAction );
    44. menu->addAction( controlAction );
    45. }
    46.  
    47. void MainWindow::createToolbars() {
    48. QToolBar *toolbar;
    49.  
    50. toolbar = addToolBar( tr("Panels") );
    51. toolbar->addAction( sceneAction );
    52. toolbar->addAction( controlAction );
    53. }
    54.  
    55. void MainWindow::showScenePanel()
    56. {
    57. sceneWindow->show();
    58. }
    59.  
    60. void MainWindow::showControlPanel()
    61. {
    62. controlWindow->show();
    63. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by 8Observer8; 23rd August 2013 at 15:02.

Similar Threads

  1. QWorkspace: child window layouts?
    By LiCodeX in forum Qt Programming
    Replies: 1
    Last Post: 13th November 2008, 07:50
  2. Removing window from QWorkspace
    By brcain in forum Qt Programming
    Replies: 2
    Last Post: 11th December 2006, 20:25
  3. Qworkspace
    By weepdoo in forum Qt Tools
    Replies: 4
    Last Post: 24th July 2006, 10:37
  4. MDI windows without QWorkspace
    By Big Duck in forum Newbie
    Replies: 2
    Last Post: 16th June 2006, 17:15
  5. QWorkspace
    By fellobo in forum Qt Programming
    Replies: 4
    Last Post: 28th April 2006, 19: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
  •  
Qt is a trademark of The Qt Company.