Page 1 of 2 12 LastLast
Results 1 to 20 of 34

Thread: QGLWidget problem

  1. #1
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default QGLWidget problem

    Hello to all!

    I've been trying for whole day to make following demand work:

    I have a QDockWidget on QMainWIndow. In this QDockWIdget I want to have an QGLWidgeet containing some animation and beneath in horiz layout two QPushButtons.

    I wrote following code:
    Qt Code:
    1. COperationWIndow::COperationWIndow(QWidget* pParent) : QDockWidget(pParent)
    2. {
    3. //setAllowedAreas(Qt::LeftDockWidgetArea); // sets allowed dock area
    4. setWindowTitle(trUtf8("Izbor ponudbe jedi in pijač")); // sets window title
    5.  
    6. // layout creation
    7. m_pVLayout=new QVBoxLayout(this); // creates new vertical layout
    8. Q_CHECK_PTR(m_pVLayout); // checks creation
    9. m_pHLayout=new QHBoxLayout(this); // creates new horizontal layout
    10. Q_CHECK_PTR(m_pHLayout); // checks creation
    11.  
    12. // creates merchandize browser
    13. m_pMerchandizeBrowser=new CMerchandizeBrowser(this); // creates new merchandize selector
    14. //m_pMerchandizeBrowser=new CMerchandizeBrowser(pParent); // creates new merchandize selector
    15. Q_CHECK_PTR(m_pMerchandizeBrowser); // checks creation
    16. m_pVLayout->addWidget(m_pMerchandizeBrowser); // adds merchandize selector to vertical layout
    17.  
    18. // creates Left Selector pushbutton
    19. m_pLeftButtonMerchandizeSelector=new QPushButton(trUtf8("Izbira levega artikla"), this);
    20. //m_pLeftButtonMerchandizeSelector=new QPushButton(trUtf8("Izbira levega artikla"), pParent);
    21. Q_CHECK_PTR(m_pLeftButtonMerchandizeSelector); // checks creation
    22.  
    23. // creates Right Selector pushbutton
    24. m_pRightButtonMerchandizeSelector=new QPushButton(trUtf8("Izbira desnegs artikla"), this);
    25. //m_pRightButtonMerchandizeSelector=new QPushButton(trUtf8("Izbira desnegs artikla"), pParent);
    26. Q_CHECK_PTR(m_pRightButtonMerchandizeSelector); // checks creation
    27.  
    28. m_pHLayout->addWidget(m_pLeftButtonMerchandizeSelector); // adds button to horiz. layout
    29. m_pHLayout->addWidget(m_pRightButtonMerchandizeSelector); // adds button to horiz. layout
    30.  
    31. m_pVLayout->addLayout(m_pHLayout); // add horiz. layout to vertical layout
    32. setLayout(m_pVLayout); // sets main layout on widget
    33. setLayout(m_pHLayout); // sets main layout on widget
    34. //setWidget(m_pMerchandizeBrowser);
    35. }
    To copy to clipboard, switch view to plain text mode 

    but this does not work. QGLWidget is not even seen, both qpushbuttons are located in the left upper corner one behind other. What the heck is going on???!!
    Qt 5.3 Opensource & Creator 3.1.2

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGLWidget problem

    Quote Originally Posted by MarkoSan View Post
    setLayout(m_pVLayout); // sets main layout on widget
    setLayout(m_pHLayout); // sets main layout on widget
    You can't set the layout twice.

  3. #3
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QGLWidget problem

    I've commented the line:
    Qt Code:
    1. setLayout(m_pHLayout); // sets main layout on widget
    To copy to clipboard, switch view to plain text mode 
    and I get same result.
    Qt 5.3 Opensource & Creator 3.1.2

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QGLWidget problem

    That is actually an interesting point - since I don't have the time to make a test program, can you answer me quick jacek, as to how does the implementation looks like when I have two layouts on a widget lets say one V box and one H box with buttons in them, all done by designer?
    Will designer generate a third layout manager to inlcude the ones I added?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QGLWidget problem

    and I get same result.
    Thats because only one layout is visible.
    You need to create one layout that will include the other two.
    And set the that layout (which includes the others) to the widget.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  6. #6
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QGLWidget problem

    I've created two layouts, as is seen from code. Vertical layout is main layout, since in this layout in the upper region should be qglwidget, and beneath the qglwidget should be in horizontal layoout two push buttons.
    Qt 5.3 Opensource & Creator 3.1.2

  7. #7
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QGLWidget problem

    in that case so include the horizontal laout in the vertical one, and set the vertical as the main layout (as you did).
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  8. #8
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QGLWidget problem

    I did that, but I still get same result.
    Qt 5.3 Opensource & Creator 3.1.2

  9. #9
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QGLWidget problem

    can you show your current code?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGLWidget problem

    Quote Originally Posted by high_flyer View Post
    how does the implementation looks like when I have two layouts on a widget lets say one V box and one H box with buttons in them, all done by designer?
    You can add a layout to another one, just like you do with widgets, and you always have a single top-level layout.

  11. #11
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QGLWidget problem

    Here is it:
    Qt Code:
    1. #include "COperationWIndow.h"
    2.  
    3. COperationWIndow::COperationWIndow(QWidget* pParent) : QDockWidget(pParent)
    4. {
    5. //setAllowedAreas(Qt::LeftDockWidgetArea); // sets allowed dock area
    6. setWindowTitle(trUtf8("Izbor ponudbe jedi in pijač")); // sets window title
    7.  
    8. // layout creation
    9. m_pVLayout=new QVBoxLayout(this); // creates new vertical layout
    10. Q_CHECK_PTR(m_pVLayout); // checks creation
    11. m_pHLayout=new QHBoxLayout(this); // creates new horizontal layout
    12. Q_CHECK_PTR(m_pHLayout); // checks creation
    13.  
    14. // creates merchandize browser
    15. m_pMerchandizeBrowser=new CMerchandizeBrowser(this); // creates new merchandize selector
    16. //m_pMerchandizeBrowser=new CMerchandizeBrowser(pParent); // creates new merchandize selector
    17. Q_CHECK_PTR(m_pMerchandizeBrowser); // checks creation
    18. m_pVLayout->addWidget(m_pMerchandizeBrowser); // adds merchandize selector to vertical layout
    19.  
    20. // creates Left Selector pushbutton
    21. m_pLeftButtonMerchandizeSelector=new QPushButton(trUtf8("Izbira levega artikla"), this);
    22. //m_pLeftButtonMerchandizeSelector=new QPushButton(trUtf8("Izbira levega artikla"), pParent);
    23. Q_CHECK_PTR(m_pLeftButtonMerchandizeSelector); // checks creation
    24.  
    25. // creates Right Selector pushbutton
    26. m_pRightButtonMerchandizeSelector=new QPushButton(trUtf8("Izbira desnegs artikla"), this);
    27. //m_pRightButtonMerchandizeSelector=new QPushButton(trUtf8("Izbira desnegs artikla"), pParent);
    28. Q_CHECK_PTR(m_pRightButtonMerchandizeSelector); // checks creation
    29.  
    30. m_pHLayout->addWidget(m_pLeftButtonMerchandizeSelector); // adds button to horiz. layout
    31. m_pHLayout->addWidget(m_pRightButtonMerchandizeSelector); // adds button to horiz. layout
    32.  
    33. m_pVLayout->addLayout(m_pHLayout); // add horiz. layout to vertical layout
    34. setLayout(m_pVLayout); // sets main layout on widget
    35. }
    36.  
    37. COperationWIndow::~COperationWIndow()
    38. {
    39. }
    To copy to clipboard, switch view to plain text mode 
    Qt 5.3 Opensource & Creator 3.1.2

  12. #12
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QGLWidget problem

    @MarkoSan:
    What happens if you do:
    Qt Code:
    1. m_pHLayout=new QHBoxLayout(m_pVLayout);
    To copy to clipboard, switch view to plain text mode 
    Ah no... QLayout is not a widget...
    Hmm I need to look this up...

    @jacek:
    and you always have a single top-level layout.
    No, when you use designer, you can have multiple "flowing" layouts on one widget, which is why I asked my question.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGLWidget problem

    Quote Originally Posted by high_flyer View Post
    you can have multiple "flowing" layouts on one widget, which is why I asked my question.
    These "flowing layouts" are QWidgets. In such case the main widget doesn't have any layouts set.

  14. #14
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QGLWidget problem

    These "flowing layouts" are QWidgets. In such case the main widget doesn't have any layouts set.
    Well, not according to the designer object browser on the right.
    Try it:
    Place 4 buttons on a widget.
    Select 2 of the buttons, and but them in a VBox layout.
    The other 2 on a another layout.
    No new widgets are to be seen on the object manager.
    That was my question - how designer implements this case.
    But I find it hard to beive that it create a new widgets for the layouts...
    See image.
    Attached Images Attached Images
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  15. #15
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QGLWidget problem

    Ok I uic'ed the ui and you arr right jecek, the uic actually cretes a widget for each layout.
    Here is the uic generated code:
    Qt Code:
    1. Dialog->resize(400, 300);
    2. widget = new QWidget(Dialog);
    3. widget->setObjectName(QString::fromUtf8("widget"));
    4. widget->setGeometry(QRect(100, 40, 162, 27));
    5. hboxLayout = new QHBoxLayout(widget);
    6. hboxLayout->setObjectName(QString::fromUtf8("hboxLayout"));
    7. hboxLayout->setContentsMargins(0, 0, 0, 0);
    8. pushButton = new QPushButton(widget);
    9. pushButton->setObjectName(QString::fromUtf8("pushButton"));
    10.  
    11. hboxLayout->addWidget(pushButton);
    12.  
    13. pushButton_2 = new QPushButton(widget);
    14. pushButton_2->setObjectName(QString::fromUtf8("pushButton_2"));
    15.  
    16. hboxLayout->addWidget(pushButton_2);
    17.  
    18. widget1 = new QWidget(Dialog);
    19. widget1->setObjectName(QString::fromUtf8("widget1"));
    20. widget1->setGeometry(QRect(90, 170, 79, 58));
    21. vboxLayout = new QVBoxLayout(widget1);
    22. vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
    23. vboxLayout->setContentsMargins(0, 0, 0, 0);
    24. pushButton_3 = new QPushButton(widget1);
    25. pushButton_3->setObjectName(QString::fromUtf8("pushButton_3"));
    26.  
    27. vboxLayout->addWidget(pushButton_3);
    28.  
    29. pushButton_4 = new QPushButton(widget1);
    30. pushButton_4->setObjectName(QString::fromUtf8("pushButton_4"));
    To copy to clipboard, switch view to plain text mode 
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  16. #16
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QGLWidget problem

    And what about me?
    Qt 5.3 Opensource & Creator 3.1.2

  17. #17
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QGLWidget problem

    @MarcoSan:
    I don't want you to think I hijacked your thread.
    This is all related actually.
    Here is a uic generated code for exatly what you are trying to do.
    Instead of your GLWidget I use a QLabel.
    Copy this implementation (not the code) and I bet yours will work as well (if you do it correctly):
    Qt Code:
    1. widget = new QWidget(Dialog); //your QDocWidget
    2.  
    3. widget->setGeometry(QRect(20, 50, 164, 49));
    4.  
    5. vboxLayout = new QVBoxLayout(widget);
    6.  
    7. vboxLayout->setContentsMargins(0, 0, 0, 0);
    8.  
    9. label = new QLabel(widget); //your QGLWidget
    10.  
    11. vboxLayout->addWidget(label);
    12.  
    13. hboxLayout = new QHBoxLayout();
    14.  
    15. pushButton = new QPushButton(widget);
    16.  
    17. hboxLayout->addWidget(pushButton);
    18.  
    19. pushButton_2 = new QPushButton(widget);
    20.  
    21. hboxLayout->addWidget(pushButton_2);
    22.  
    23.  
    24. vboxLayout->addLayout(hboxLayout);
    To copy to clipboard, switch view to plain text mode 
    Last edited by high_flyer; 7th December 2007 at 19:10.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  18. The following user says thank you to high_flyer for this useful post:

    MarkoSan (11th January 2008)

  19. #18
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QGLWidget problem

    I am lookng at code chunk you posted and I concentrate on layouts. I have the same layout implementation as you. Is it possible QGLWidget cannot be placed on QDockWidget?

    And what is the purpose of setObjectName method in your code? What are you trying to achieve with that?
    Qt 5.3 Opensource & Creator 3.1.2

  20. #19
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QGLWidget problem

    Try this:
    Qt Code:
    1. m_pHLayout=new QHBoxLayout(/*this*/);
    To copy to clipboard, switch view to plain text mode 
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  21. #20
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QGLWidget problem

    A QDockWidget acts as a wrapper for its child widget, set with setWidget().
    May be you should try to create a QWidget, put all your stuff with the layouts on it, and add that widget to the dock widget.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Serious problem with QGLWidget
    By al101 in forum Qt Programming
    Replies: 12
    Last Post: 27th April 2007, 13:52
  2. why linking problem with QGLWidget???
    By Shuchi Agrawal in forum Newbie
    Replies: 17
    Last Post: 16th March 2007, 10:45
  3. Problem combining QWorkspace & QGLWidget
    By Nb2Qt in forum Qt Programming
    Replies: 1
    Last Post: 18th December 2006, 21:45
  4. QGLWidget renderText problem
    By mbjerkne in forum Qt Programming
    Replies: 1
    Last Post: 7th April 2006, 21:35
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.