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

Thread: QGLWidget problem

  1. #21
    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

    Is it possible to place all controls I need directly to QMainWIndow? So there is no more need of any "foundation" widgets?
    Qt 5.3 Opensource & Creator 3.1.2

  2. #22
    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
    Is it possible to place all controls I need directly to QMainWIndow? So there is no more need of any "foundation" widgets?
    No, QMainWindow has a special layout that you can't change, but you can use QWidget instead.

  3. #23
    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

    Quote Originally Posted by jacek View Post
    No, QMainWindow has a special layout that you can't change, but you can use QWidget instead.
    So, I try following:

    On QMainWindow, I create QWidget and then I setup it as QMainWindow's central widget?
    Qt 5.3 Opensource & Creator 3.1.2

  4. #24
    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
    On QMainWindow, I create QWidget and then I setup it as QMainWindow's central widget?
    Yes, of course the main window takes the ownership of this widget, so you don't have to care about its deletion.

  5. #25
    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

    Quote Originally Posted by MarkoSan View Post
    So, I try following:

    On QMainWindow, I create QWidget and then I setup it as QMainWindow's central widget?
    I did that and it WORKS!

    Thanks a lot to all of you
    Qt 5.3 Opensource & Creator 3.1.2

  6. #26
    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

    Question Re: QGLWidget problem

    Well, I simply do not get it anymore. Here is the code. Now I want to add an QTableWidget near QGLWidget and I get same problem over again. I add to layout using:
    Qt Code:
    1. m_pVLayout->addLayout(m_pHLayout); // add horiz. layout to vertical layout
    2. m_pMainLayout->addLayout(m_pVLayout); // adds vert. layout to main layout
    3. m_pMainLayout->addWidget(m_pMerchandizeTable); // adds merchandize table to layout
    4. //m_pMainLayout->addWidget(pTWidget); // test
    5. //setLayout(m_pVLayout); // sets main layout on widget
    6. setLayout(m_pMainLayout); // sets main layout on widget
    To copy to clipboard, switch view to plain text mode 

    and table widget is visibible, but in upper left corner again. Why????!!!
    Qt 5.3 Opensource & Creator 3.1.2

  7. #27
    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

    What widget do you call the setLayout() method on? And why can't you use Qt Designer?

  8. #28
    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

    Question Re: QGLWidget problem

    Well, setLayout is called on class COperationWindow (derived from QWidget), which contains QGLWidget, QLabel and three QPusbuttons. Here is a code:
    Qt Code:
    1. #include "COperationWIndow.h"
    2.  
    3. COperationWIndow::COperationWIndow(QWidget* pParent) : QWidget(pParent)
    4. //COperationWIndow::COperationWIndow(QWidget* pParent) : QDockWidget(pParent)
    5. {
    6. //setAllowedAreas(Qt::LeftDockWidgetArea); // sets allowed dock area
    7. //setWindowOpacity(rDefaultWindowOpacity); // sets window opacity
    8. setWindowTitle(trUtf8("Jedilni list")); // sets window title
    9.  
    10. QFont m_cFont("1942 report", 72, QFont::Bold); // sets up font
    11. //QFont m_cFont("Mom´sTypewriter", 72, QFont::Bold); // sets up font
    12. //m_cFont.setStretch(QFont::UltraCondensed); // sets strech factor
    13.  
    14. // sets black background for this window
    15. setAutoFillBackground(true);
    16. m_cPalette=this->palette(); // gets current pallete of current widget
    17. m_cPalette.setColor(QPalette::Background, Qt::black); // sets background color of widget
    18. this->setPalette(m_cPalette);
    19.  
    20. // layout creation
    21. m_pVLayout=new QVBoxLayout(this); // creates new vertical layout
    22. Q_CHECK_PTR(m_pVLayout); // checks creation
    23. m_pHLayout=new QHBoxLayout(this); // creates new horizontal layout
    24. Q_CHECK_PTR(m_pHLayout); // checks creation
    25. m_pMainLayout=new QHBoxLayout(this); // creates main layout
    26. Q_CHECK_PTR(m_pMainLayout); // checks creation
    27.  
    28. // creates merchandize browser
    29. m_pMerchandizeBrowser=new CMerchandizeBrowser(this); // creates new merchandize selector
    30. //m_pMerchandizeBrowser=new CMerchandizeBrowser(pParent); // creates new merchandize selector
    31. Q_CHECK_PTR(m_pMerchandizeBrowser); // checks creation
    32.  
    33. // creates Left Selector pushbutton
    34. m_pLeftButtonMerchandizeSelector=new QPushButton(trUtf8("Levo"), this);
    35. //m_pLeftButtonMerchandizeSelector=new QPushButton(trUtf8("Izbira levega artikla"), pParent);
    36. Q_CHECK_PTR(m_pLeftButtonMerchandizeSelector); // checks creation
    37. //m_pLeftButtonMerchandizeSelector->setFlat(true); // sets flat flag
    38. // sets new size
    39. //m_pLeftButtonMerchandizeSelector->resize(iMerchandizeButtonSelectorWidth, iMerchandizeButtonSelectorHeight);
    40. connect(m_pLeftButtonMerchandizeSelector,
    41. SIGNAL(clicked()),
    42. this,
    43. SLOT(showLeftMerchandize()));
    44.  
    45. // creates merchandizer confirmer
    46. m_pButtonMerchandizeConfirmer=new QPushButton(trUtf8("IZBERI"), this);
    47. Q_CHECK_PTR(m_pButtonMerchandizeConfirmer);
    48. connect(m_pButtonMerchandizeConfirmer,
    49. SIGNAL(clicked()),
    50. this,
    51. SLOT(chooseMerchandize()));
    52.  
    53. // creates Right Selector pushbutton
    54. m_pRightButtonMerchandizeSelector=new QPushButton(trUtf8("Desno"), this);
    55. //m_pRightButtonMerchandizeSelector=new QPushButton(trUtf8("Izbira desnegs artikla"), pParent);
    56. Q_CHECK_PTR(m_pRightButtonMerchandizeSelector); // checks creation
    57. //m_pRightButtonMerchandizeSelector->setFlat(true); // sets flat flag
    58. // sets new size
    59. //m_pRightButtonMerchandizeSelector->resize(iMerchandizeButtonSelectorWidth, iMerchandizeButtonSelectorHeight);
    60. connect(m_pRightButtonMerchandizeSelector,
    61. SIGNAL(clicked()),
    62. this,
    63. SLOT(showRightMerchandize()));
    64.  
    65. // left button color setup
    66. m_cPalette=m_pLeftButtonMerchandizeSelector->palette(); // gets current pallete of button "Left"
    67. m_cPalette.setColor(QPalette::Button, Qt::black); // sets up new palette componenet
    68. m_cPalette.setColor(QPalette::ButtonText, Qt::white); // sets up new palette componenet
    69. m_pLeftButtonMerchandizeSelector->setPalette(m_cPalette); // sets new pallete
    70. m_pLeftButtonMerchandizeSelector->setFont(m_cFont); // sets new font
    71.  
    72. // confirmer button color setup
    73. m_cPalette=m_pButtonMerchandizeConfirmer->palette(); // gets current pallete of button "Left"
    74. m_cPalette.setColor(QPalette::Button, Qt::blue); // sets up new palette componenet
    75. m_cPalette.setColor(QPalette::ButtonText, Qt::black); // sets up new palette componenet
    76. m_pButtonMerchandizeConfirmer->setPalette(m_cPalette); // sets new pallete
    77. m_pButtonMerchandizeConfirmer->setFont(m_cFont); // sets new font
    78.  
    79. // right button color setup
    80. m_cPalette=m_pRightButtonMerchandizeSelector->palette(); // gets current pallete of button "Right"
    81. m_cPalette.setColor(QPalette::Button, Qt::black); // sets up new palette componenet
    82. m_cPalette.setColor(QPalette::ButtonText, Qt::white); // sets up new palette componenet
    83. m_pRightButtonMerchandizeSelector->setPalette(m_cPalette); // sets new pallete
    84. m_pRightButtonMerchandizeSelector->setFont(m_cFont); // sets new font
    85.  
    86. // TODO: show selected merchandize name and price
    87.  
    88. // table of ordered merchandize creation
    89. /*
    90.   m_pMerchandizeTable=new QTableWidget(this); // creates new table
    91.   Q_CHECK_PTR(m_pMerchandizeTable); // checks creation
    92.   m_pMerchandizeTable->setColumnCount(iNrColumns); // sets number of columns
    93.   m_pMerchandizeTable->setRowCount(iNrRows); // sets number of rows
    94. */
    95.  
    96. // selected merchandize name label widget
    97. m_pMerchandizeNameLabel=new QLabel(this); // creates new label
    98. Q_CHECK_PTR(m_pMerchandizeNameLabel); // checks creation
    99. m_cPalette=m_pMerchandizeNameLabel->palette(); // geta label palette
    100. m_cPalette.setColor(QPalette::Text, QColor(240, 167, 16)); // sets palette color
    101. QFont labelFont("Rothenburg Decorative", 36, QFont::Bold); // sets up new font
    102. m_pMerchandizeNameLabel->setFont(labelFont); // sets font
    103. m_pMerchandizeNameLabel->setFrameStyle(QFrame::Sunken); // sets decoration
    104. // sets selected merchandize name
    105. m_pMerchandizeNameLabel->setText(m_pMerchandizeBrowser->getMerchandizeName(m_pMerchandizeBrowser->getSelected()));
    106. m_pMerchandizeNameLabel->setAlignment(Qt::AlignCenter); // set text justification to "centering"
    107. qDebug() << m_pMerchandizeBrowser->getMerchandizeName(m_pMerchandizeBrowser->getSelected());
    108.  
    109. // layouts setup
    110. m_pHLayout->addWidget(m_pLeftButtonMerchandizeSelector); // adds button to horiz. layout
    111. m_pHLayout->addWidget(m_pButtonMerchandizeConfirmer); // adds a button to horiz. layout
    112. m_pHLayout->addWidget(m_pRightButtonMerchandizeSelector); // adds button to horiz. layout
    113.  
    114. m_pVLayout->addWidget(m_pMerchandizeBrowser); // adds merchandize selector to vertical layout
    115. m_pVLayout->addWidget(m_pMerchandizeNameLabel); // adds merchandize name label to vertical layout
    116. m_pVLayout->addLayout(m_pHLayout); // add horiz. layout to vertical layout
    117. m_pMainLayout->addLayout(m_pVLayout); // adds vert. layout to main layout
    118. //m_pMainLayout->addWidget(m_pMerchandizeTable); // adds merchandize table to layout
    119. setLayout(m_pMainLayout); // sets main layout on widget
    120.  
    121. // creats new timer, binded to main application object
    122. /*
    123.   QPointer<QTimer> m_pAdvertisementTimer=new QTimer(this);
    124.   Q_CHECK_PTR(m_pAdvertisementTimer); // checks creation
    125.   connect(m_pAdvertisementTimer, SIGNAL(timeout()), this, SLOT(startAdvertising()));
    126.   m_pAdvertisementTimer->start(iAdvertisingTimeout); // restarts advertisement timer
    127. */
    128. }
    129.  
    130. void COperationWIndow::showLeftMerchandize()
    131. {
    132. m_iSelected=m_pMerchandizeBrowser->getSelected()-1; // selects left merchandize
    133. m_pMerchandizeBrowser->setSelected(m_iSelected);
    134. m_pMerchandizeNameLabel->setText(m_pMerchandizeBrowser->getMerchandizeName(m_pMerchandizeBrowser->getSelected()));
    135. m_pMerchandizeNameLabel->setAlignment(Qt::AlignCenter); // set text justification to "centering"
    136. m_pMerchandizeBrowser->update();
    137. //m_pAdvertisementTimer->start(iAdvertisingTimeout); // restarts advertisement timer
    138. }
    139.  
    140. void COperationWIndow::showRightMerchandize()
    141. {
    142. m_iSelected=m_pMerchandizeBrowser->getSelected()+1; // selects left merchandize
    143. m_pMerchandizeBrowser->setSelected(m_iSelected);
    144. m_pMerchandizeNameLabel->setText(m_pMerchandizeBrowser->getMerchandizeName(m_pMerchandizeBrowser->getSelected()));
    145. m_pMerchandizeNameLabel->setAlignment(Qt::AlignCenter); // set text justification to "centering"
    146. m_pMerchandizeBrowser->update(); // showa selected merchandize
    147. //m_pAdvertisementTimer->start(iAdvertisingTimeout); // restarts advertisement timer
    148. }
    149.  
    150. // slot for choosing merchandize
    151. void COperationWIndow::chooseMerchandize()
    152. {
    153. }
    154.  
    155. // slot for showing advertisement banners
    156. void COperationWIndow::startAdvertising()
    157. {
    158. }
    159.  
    160. COperationWIndow::~COperationWIndow()
    161. {
    162. }
    To copy to clipboard, switch view to plain text mode 
    I do not use designet because I simply do not like it. And by the way, Qlabel DOES NOT show any text and this is simply driving me mad right now. And I know I've momentaly commented the code regarding QTableWidget, it's for testing purposes only, nevertheless, once qtablewidget code is uncommented the problem remains.
    Qt 5.3 Opensource & Creator 3.1.2

  9. #29
    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
    m_pVLayout=new QVBoxLayout(this); // creates new vertical layout
    Q_CHECK_PTR(m_pVLayout); // checks creation
    m_pHLayout=new QHBoxLayout(this); // creates new horizontal layout
    Q_CHECK_PTR(m_pHLayout); // checks creation
    m_pMainLayout=new QHBoxLayout(this); // creates main layout
    Q_CHECK_PTR(m_pMainLayout); // checks creation
    You shouldn't pass "this" to layouts' constructors, because they will call setLayout() on the parent.

    Quote Originally Posted by MarkoSan View Post
    I do not use designet because I simply do not like it.
    Like it or not, but it would take you only a couple of minutes to set up this widget in Qt Designer.

    Quote Originally Posted by MarkoSan View Post
    And by the way, Qlabel DOES NOT show any text and this is simply driving me mad right now.
    Because you should use QPalette::WindowText instead of QPalette::Text and you have to set the changed palette back on the label to see the effect.

  10. #30
    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

    Quote Originally Posted by jacek View Post
    You shouldn't pass "this" to layouts' constructors, because they will call setLayout() on the parent.


    Like it or not, but it would take you only a couple of minutes to set up this widget in Qt Designer.


    Because you should use QPalette::WindowText instead of QPalette::Text and you have to set the changed palette back on the label to see the effect.
    Jacek, thanks on tip on QLabel, it works now. But whenever I create Layouts with "this" parameter or without, result of placing QWIdgetTable is still the same.
    Qt 5.3 Opensource & Creator 3.1.2

  11. #31
    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
    whenever I create Layouts with "this" parameter or without, result of placing QWIdgetTable is still the same.
    Is this what you are trying to achieve?
    Attached Images Attached Images

  12. #32
    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

    Yessssssss! But whatever I do, I get same result: QTableWidget is in upper left corner and therefore this is NOT ok. I want result excatly as on your pic.
    Qt 5.3 Opensource & Creator 3.1.2

  13. #33
    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

    That's weird, because I've just uncommented the m_pMerchandizeTable lines (including the one with addWidget()). Run "make clean" and make sure you don't pass any parents to layout constructors.

  14. The following user says thank you to jacek for this useful post:

    MarkoSan (8th December 2007)

  15. #34
    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

    Quote Originally Posted by jacek View Post
    That's weird, because I've just uncommented the m_pMerchandizeTable lines (including the one with addWidget()). Run "make clean" and make sure you don't pass any parents to layout constructors.
    I deleted manually all ..\debug\ files and now it works. I do not get it what was wrong. Jacek, thanks!!!
    Qt 5.3 Opensource & Creator 3.1.2

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
  •  
Qt is a trademark of The Qt Company.