Results 1 to 20 of 21

Thread: layout in widget give me an empty window!

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default layout in widget give me an empty window!

    Hi,
    i have Splitter and i make like that
    Qt Code:
    1. QVBoxLayout *mVerticalLayout;
    2. QSplitter *Splitter = new QSplitter(this);
    3. Splitter->setOrientation(Qt::Vertical);
    4. mVerticalLayout->addWidget(Splitter);
    5.  
    6. QRenderWindow *orw = new QRenderWindow(Splitter);
    7. mQRenderWindowList.append(orw);
    8. Splitter->addWidget(orw);
    To copy to clipboard, switch view to plain text mode 
    and that work very good
    But i want now add name of each Splitter( i want to see the name) for that i change the method and i use qgroubbox
    But that does not work
    i make like that

    Qt Code:
    1. QHBoxLayout *mVerticalLayout;
    2. QWidget *central = new QGroupBox("My Scene", this);
    3.  
    4.  
    5. QOgreRenderWindow *orw = new QOgreRenderWindow(central);
    6.  
    7. mVerticalLayout->addWidget(orw);
    8. central->setLayout(mVerticalLayout);
    To copy to clipboard, switch view to plain text mode 

    But that make to me an empty window
    Last edited by rimie23; 3rd June 2012 at 09:35.

  2. #2
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Widget in layout give me an empty window!

    i tried to make like that
    Qt Code:
    1. QWidget *central = new QGroupBox("My Scene", this);
    2.  
    3.  
    4. QRenderWindow *orw = new QRenderWindow();
    5. mQOgreRenderWindowList.append(orw);
    6.  
    7. mVerticalLayout->addWidget(central);
    8. mVerticalLayout->addWidget(orw);
    To copy to clipboard, switch view to plain text mode 
    i see the groupbox "my scene" in the left of window and the render window (orw) in the right of window
    i can't make the orw in the groupbox
    Last edited by rimie23; 3rd June 2012 at 17:51.

  3. #3
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: layout in widget give me an empty window!

    when i change this line
    Qt Code:
    1. mVerticalLayout-> addWidget(central);
    To copy to clipboard, switch view to plain text mode 
    by this
    Qt Code:
    1. central->setLayout(mVerticalLayout);
    To copy to clipboard, switch view to plain text mode 

    i see an empty window (there no groupbox, no scene)

  4. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: layout in widget give me an empty window!

    the rules are simple.

    if a widget has a parent, it is shown in the parent.

    if a layout is set on a widget, the widget is now the parent of all Widgets in the layout.

    that is all you need to know.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: layout in widget give me an empty window!

    @Rimie: If you want assistance with code it helps if you post complete copy-and-paste chunks or, better still, a self-contained complete program that shows the problem, rather than assorted fragments. We ultimately have no idea what you have actually done because none of the fragments is complete and subsequent amendments depend on knowing where and to what you have applied them.

    You may be better off using Qt Designer either standalone or inside Qt Creator. Either way, you must read Layout Management or you will waste a lot of time.

    I am going to assume this is a continuation of your earlier posts of a similar flavour. Here is a complete example of two fake Ogre widgets in a splitter. The left widget in the splitter has a group box label, and the one on the right does not... so you can compare.
    Qt Code:
    1. #include <QtGui>
    2. #include <QDebug>
    3.  
    4. class FakeOgreWidget: public QLabel
    5. {
    6. public:
    7. FakeOgreWidget(QWidget *p = 0): QLabel("Fake Ogre Widget", p) { }
    8. };
    9.  
    10. class LabeledOgreWidget: public QGroupBox
    11. {
    12. public:
    13. LabeledOgreWidget(const QString &label, QWidget *p = 0):
    14. QGroupBox(label, p)
    15. {
    16. QVBoxLayout *layout = new QVBoxLayout(this);
    17. layout->addWidget(new FakeOgreWidget(this));
    18. setLayout(layout);
    19. }
    20. };
    21.  
    22.  
    23. class MainWindow: public QMainWindow {
    24. Q_OBJECT
    25. public:
    26. MainWindow(QWidget *p = 0): QMainWindow(p) {
    27. QSplitter *splitter = new QSplitter(this);
    28. splitter->addWidget(new LabeledOgreWidget("Left", splitter));
    29. splitter->addWidget(new FakeOgreWidget(splitter));
    30.  
    31. setCentralWidget(splitter);
    32. }
    33.  
    34. private:
    35. };
    36.  
    37. int main(int argc, char *argv[])
    38. {
    39. QApplication app(argc, argv);
    40.  
    41. MainWindow m;
    42. m.resize(640, 480);
    43. m.show();
    44. return app.exec();
    45. }
    46. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: layout in widget give me an empty window!

    thank you for repling
    Qt Code:
    1. If you want assistance with code it helps if you post complete copy-and-paste chunks or, better still, a self-contained complete program that shows the problem
    To copy to clipboard, switch view to plain text mode 
    i did not copy all the code because it have not relation of this problem (it is not in qt ) i know that because my program work very well when i just make that

    Qt Code:
    1. void QWidget::setViewNum(int num)
    2. {
    3. if(num == 1)
    4. {
    5. QVBoxLayout *mVerticalLayout;
    6. QSplitter *Splitter = new QSplitter(this);
    7. Splitter->setOrientation(Qt::Vertical);
    8. mVerticalLayout->addWidget(Splitter);
    9.  
    10. QRenderWindow *orw = new QRenderWindow(Splitter);
    11. mQRenderWindowList.append(orw);
    12. Splitter->addWidget(orw);
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 
    and QRenderWindow is like that
    Qt Code:
    1. QRenderWindow::QRenderWindow(QWidget *parent) : QWidget(parent)
    To copy to clipboard, switch view to plain text mode 
    and in mainwindow i make like that
    Qt Code:
    1. MainWindow::MainWindow()
    2. {
    3. mQWidget = new QWidget(this);
    4. setCentralWidget(mQWidget);
    To copy to clipboard, switch view to plain text mode 
    all that work good i can see my object in the splitter

    But when i want use groupbox that do not work (i see just an empty window, you can see my code in the firt or the second post )

    I hope that what i write now it help you to see where is my problem exactelly
    Last edited by rimie23; 4th June 2012 at 08:16.

  7. #7
    Join Date
    Apr 2011
    Location
    Russia
    Posts
    85
    Thanks
    2
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: layout in widget give me an empty window!

    Qt Code:
    1. QWidget *central = new QGroupBox("My Scene", this);
    2.  
    3. QOgreRenderWindow *orw = new QOgreRenderWindow(central);
    4.  
    5. QHBoxLayout *mVerticalLayout = new QHBoxLayout(central);
    6. mVerticalLayout->addWidget(orw);
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: layout in widget give me an empty window!

    thanks Jonny
    But it dos not work it still empty window

  9. #9
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: layout in widget give me an empty window!

    Quote Originally Posted by rimie23 View Post
    thank you for repling
    Qt Code:
    1. If you want assistance with code it helps if you post complete copy-and-paste chunks or, better still, a self-contained complete program that shows the problem
    To copy to clipboard, switch view to plain text mode 
    i did not copy all the code because it have not relation of this problem (it is not in qt ) i know that because my program work very well when i just make that
    you will note that he said 'self-contained complete program' - this DOES NOT have to be your whole program - it should be a self-contained complete program. Comprendes?

    Quote Originally Posted by rimie23 View Post
    thanks Jonny
    But it dos not work it still empty window

    how about you post a self-contained complete program that doesnt work, and we will help with what is wrong.

    I never trust anyone that says 'it doesn't work' when they have not shown us *what* doesnt work.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  10. #10
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: layout in widget give me an empty window!

    "it should be a self-contained complete program."
    do not you mean all the program ?
    because as exemple "QOgreRenderWindow" containd many things have not relation with qt

    Sory than what you mean by " self-contained complete program"

    Edit : i work with ogre+qt , if you can integrate ogre i have not problem to give you version (code) that work with splitter and do not work when i add the groupbox (if i understand good the
    " " self-contained complete program" that mean program where you can execute it and you can't execute it if you have not ogre)
    else if it's just code where i have qt look

    Qogrewidget have this member
    Qt Code:
    1. #ifndef QOGREWIDGET_H
    2. #define QOGREWIDGET_H
    3.  
    4. #include <QWidget>
    5. #include <QVBoxLayout>
    6. #include <QSplitter>
    7. #include <QList>
    8.  
    9. #include <OGRE/Ogre.h>
    10.  
    11. #include "QOgreRenderWindow.h"
    12.  
    13. class QOgreRenderWindow;
    14. class QOgreWidget : public QWidget, public Ogre::FrameListener
    15. {
    16. Q_OBJECT
    17.  
    18. public:
    19.  
    20.  
    21. QOgreWidget(QWidget *parent = 0);
    22. ~QOgreWidget();
    23. Ogre::Root *mRoot;
    24. QHBoxLayout *mVerticalLayout;
    25.  
    26. QList<QOgreRenderWindow*> getOgreWindows() { return mQOgreRenderWindowList; }
    27. int nb_cam;
    28. private:
    29. Ogre::RenderWindow *mRenderWindow;
    30. Ogre::SceneManager* mSceneMgr;
    31.  
    32.  
    33. QList<QOgreRenderWindow*> mQOgreRenderWindowList;
    34. int mainProcessID;
    35. void init();
    36. void initResources();
    37. void createScene();
    38. void timerEvent(QTimerEvent* evt);
    39. protected:
    40. virtual bool frameStarted(const Ogre::FrameEvent& evt);
    41. virtual bool frameEnded(const Ogre::FrameEvent& evt);
    42.  
    43.  
    44. virtual void showEvent(QShowEvent *evt);
    45.  
    46.  
    47.  
    48.  
    49. public slots:
    50.  
    51. void setViewNum(int num);
    52.  
    53. private:
    54. Ogre::Vector3 cPosition;
    55. Ogre::Entity* ogreCube;
    56. Ogre::SceneNode* CubeNode;
    57. };
    58.  
    59. #endif // QOGREWIDGET_H
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. QOgreWidget::QOgreWidget(QWidget *parent) :
    2. QWidget(parent),
    3.  
    4. mSceneMgr(NULL)
    5. {
    6.  
    7. mRenderWindow = NULL;
    8.  
    9. mVerticalLayout = new QHBoxLayout(this);
    10. }void QOgreWidget::setViewNum(int num)
    11. {
    12. for(int i = 0;i<mQOgreRenderWindowList.count();i++)
    13. {
    14. delete mQOgreRenderWindowList.takeAt(i);
    15. i--;
    16. }
    17.  
    18. for(int i = 0; i<mVerticalLayout->count();i++)
    19. {
    20. delete mVerticalLayout->takeAt(i);
    21. i--;
    22. }
    23.  
    24. if(num == 1)
    25. {
    26. /* QWidget *central = new QGroupBox("My Scene", this);
    27.  
    28.  
    29.  
    30.   mQOgreRenderWindowList.append(orw);
    31.  
    32.   mVerticalLayout->addWidget(central);
    33.   mVerticalLayout->addWidget(orw); */QOgreRenderWindow * orw = new QOgreRenderWindow(QString("View1"),mSceneMgr,mRoot,nb_cam/*,central*/);
    34. mVerticalLayout->addWidget(orw);
    35. QWidget *central = new QGroupBox("My Scene",orw);
    36. // mVerticalLayout->addWidget(central);
    37. central->setLayout(mVerticalLayout);
    38. }
    39.  
    40. //////////////////////
    41. all the code here has relation with ogre not with qt
    42. ///////////////////////
    43. void QOgreWidget::setViewNum(int num)//It is slot
    44. {
    45.  
    46. QSplitter *Splitter = new QSplitter(this);
    47. Splitter->setOrientation(Qt::Vertical);
    48. mVerticalLayout->addWidget(Splitter);
    49.  
    50. QRenderWindow *orw = new QRenderWindow(Splitter);
    51. mQRenderWindowList.append(orw);
    52. Splitter->addWidget(orw);
    53. if(num == 4)
    54. {
    55.  
    56. QSplitter *Splitter = new QSplitter(this);
    57. Splitter->setOrientation(Qt::Vertical);
    58. QSplitter *Splitter2 = new QSplitter(Splitter);
    59. Splitter2->setOrientation(Qt::Horizontal);
    60.  
    61. Splitter->addWidget(Splitter2);
    62.  
    63. QSplitter *Splitter3 = new QSplitter(Splitter);
    64. Splitter3->setOrientation(Qt::Horizontal);
    65.  
    66. Splitter->addWidget(Splitter3);
    67.  
    68. mVerticalLayout->addWidget(Splitter);
    69.  
    70. QOgreRenderWindow *orw = new QOgreRenderWindow(Splitter2);
    71. mQOgreRenderWindowList.append(orw);
    72. Splitter2->addWidget(orw);
    73.  
    74. orw = new QOgreRenderWindow(Splitter3);
    75. mQOgreRenderWindowList.append(orw);
    76. Splitter3->addWidget(orw);
    77.  
    78. orw = new QOgreRenderWindow(Splitter3);
    79. mQOgreRenderWindowList.append(orw);
    80. Splitter3->addWidget(orw);
    81.  
    82. orw = new QOgreRenderWindow(Splitter3);
    83. mQOgreRenderWindowList.append(orw);
    84. Splitter3->addWidget(orw);
    85.  
    86.  
    87. }
    88. }
    To copy to clipboard, switch view to plain text mode 

    the class QOGRERENDERWINDOW
    Qt Code:
    1. #ifndef QOGRERENDERWINDOW_H
    2. #define QOGRERENDERWINDOW_H
    3.  
    4. #include <QWidget>
    5. #include <QPaintEngine>
    6. #include <QPaintEvent>
    7. #include <QResizeEvent>
    8.  
    9. #include <OGRE/Ogre.h>
    10. #include "my_interface.h"
    11.  
    12. class QOgreRenderWindow : public QWidget
    13. {
    14. Q_OBJECT
    15. public:
    16.  
    17.  
    18. QOgreRenderWindow(QWidget *parent = 0);
    19. ~QOgreRenderWindow();
    20.  
    21.  
    22.  
    23. private:
    24. QString mWindowName;
    25. Ogre::SceneManager* mSceneMgr;
    26. Ogre::RenderWindow* mRenderWindow;
    27. Ogre::Camera *mCamera;
    28. int nb_cam;
    29. Ogre::Viewport* mVp;
    30. Ogre::Root *mRoot;
    31. void init();
    32. void createOrbitalCamera();
    33.  
    34. protected:
    35. virtual QPaintEngine* paintEngine() const { return 0; }
    36. virtual void paintEvent(QPaintEvent* evt);
    37. virtual void resizeEvent(QResizeEvent* evt);
    38. virtual void keyPressEvent(QKeyEvent* evt);
    39. virtual void keyReleaseEvent(QKeyEvent* evt);
    40.  
    41. virtual void mouseReleaseEvent(QMouseEvent* evt);
    42.  
    43. virtual void wheelEvent(QWheelEvent * evt);
    44. };
    45.  
    46. #endif // QOGRERENDERWINDOW_H
    To copy to clipboard, switch view to plain text mode 
    on mainwindow
    Qt Code:
    1. MainWindow::MainWindow()
    2. {
    3. mQOgreWidget = new QOgreWidget(this);
    4.  
    5. setCentralWidget(mQOgreWidget);
    6. }
    7. void MainWindow::setViewNum(int num)
    8. {
    9. mQOgreWidget->setViewNum(num);
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 
    in main
    Qt Code:
    1. int main(int argc, char **argv)
    2. {
    3. QApplication app(argc, argv);
    4. MainWindow window;
    5. window.show();
    6. window.setViewNum(1);
    7. return app.exec();
    8. }
    To copy to clipboard, switch view to plain text mode 

    that all my code that he has not relation with ogre (the rest is in ogre , c++) , that code with the code in ogre the result is an object in window (splitter ) or 4 view in each view i see my object
    if i add groupbox(with the code in my first reply ) i do not see the object

    I hope with this code i give you"self-contained complete program" (and i said to you i can give you version of my program with ogre)
    Last edited by rimie23; 4th June 2012 at 16:11.

  11. #11
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: layout in widget give me an empty window!

    self contained + complete - means you show ALL code from an EXAMPLE program that has the *same* problem. You do *not* need ogre to show any problem with widgets and layouts.

    As nobody can copy + paste your code and make it compile (with suitable pro file), then no, your code is not complete. Ogre has nothing at all to do with a problem with a groupbox. Make your example much simpler without any ogre.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar Threads

  1. put widget in layout
    By rimie23 in forum Qt Programming
    Replies: 5
    Last Post: 28th May 2012, 09:56
  2. mainwindow layout vs widget layout
    By fatecasino in forum Newbie
    Replies: 2
    Last Post: 14th December 2010, 14:45
  3. How to change a widget to other widget in layout?
    By Kevin Hoang in forum Qt Programming
    Replies: 2
    Last Post: 20th March 2010, 10:55
  4. Widget layout in GridLayout
    By Dato0011 in forum Qt Programming
    Replies: 8
    Last Post: 7th December 2009, 09:26
  5. Stacked Layout. & Widget.
    By csvivek in forum Qt Programming
    Replies: 1
    Last Post: 13th May 2008, 08:56

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.