Results 1 to 2 of 2

Thread: odd double widgets

  1. #1
    Join Date
    Jun 2007
    Posts
    25
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question odd double widgets

    Hi,
    Sorry for long code post below. I'm struggling with a drop dead simple example of placing a soqtexaminerviewer in a qt window. This code is streamlined from exs. by Jon Andrews and others. There's an odd issue of the viewer's widgets doubling.

    I can defeat some of that behavior by turning off decorations, or getting the buttons then reducing the number etc. but that doesn't solve the basic problem of why the widgets are doubling up in the first place.

    If you comment out "this->setBaseWidget(widget);" you can clearly see a small version of the soqtexaminer viewer in the upper left hand corner ot the qt window. Strange?

    I've tweaked with class signatures, layout manager, the show method etc. I can't seem to figure out what's going wrong.

    Wondering if anyone else is working along same lines, and might have an idea.

    thanks,



    Qt Code:
    1. //main.cpp
    2.  
    3. # define COIN_DLL
    4. # define SOQT_NOT_DLL
    5. # define SIMAGE_DLL
    6.  
    7. #include <QApplication>
    8. #include "window.h"
    9.  
    10. int main(int argc, char *argv[])
    11. {
    12. QApplication app(argc, argv);
    13. Qt::Alignment topRight = Qt::AlignRight | Qt::AlignTop;
    14.  
    15. Window window;
    16. window.show();
    17. return app.exec();
    18. }
    19.  
    20. //==============
    21. //window.h
    22.  
    23. # define COIN_DLL
    24. # define SOQT_NOT_DLL
    25. # define SIMAGE_DLL
    26.  
    27. #ifndef WINDOW_H
    28. #define WINDOW_H
    29.  
    30. #include <QWidget>
    31. class CoinWidget;
    32.  
    33.  
    34. class Window : public QWidget
    35. {
    36. Q_OBJECT
    37.  
    38. public:
    39. Window();
    40.  
    41. private:
    42.  
    43. QHBoxLayout *rootLayout;
    44. CoinWidget *coinWidget;
    45. };
    46. #endif
    47.  
    48. //==============
    49. //window.cpp
    50.  
    51. # define COIN_DLL
    52. # define SOQT_NOT_DLL
    53. # define SIMAGE_DLL
    54.  
    55. #include <QtGui>
    56. #include "coinwidget.h"
    57. #include "window.h"
    58.  
    59. Window::Window()
    60. {
    61. coinWidget = new CoinWidget;
    62. rootLayout = new QHBoxLayout;
    63. rootLayout->addWidget(coinWidget);
    64. setLayout(rootLayout);
    65. }
    66. //==============
    67. //coinwidget.h
    68.  
    69. # define COIN_DLL
    70. # define SOQT_NOT_DLL
    71. # define SIMAGE_DLL
    72.  
    73. #ifndef COINWIDGET_H
    74. #define COINWIDGET_H
    75.  
    76. #include <QMainWindow>
    77. #include <Inventor/Qt/SoQt.h>
    78.  
    79. //Forward declarations
    80. class Model;
    81.  
    82. class CoinWidget : public QMainWindow
    83. {
    84. Q_OBJECT
    85.  
    86. public:
    87. CoinWidget(QWidget *parent = 0);
    88. ~CoinWidget();
    89.  
    90. QSize minimumSizeHint() const;
    91. QSize sizeHint() const;
    92.  
    93. protected:
    94. Model *model;
    95.  
    96. };
    97. #endif
    98.  
    99. //==============
    100. //coinwidget.cpp
    101.  
    102. # define COIN_DLL
    103. # define SOQT_NOT_DLL
    104. # define SIMAGE_DLL
    105.  
    106. #include <QtGui>
    107. #include <QtCore>
    108. #include <Inventor/Qt/SoQt.h>
    109. #include <Inventor/Qt/viewers/SoQtExaminerViewer.h>
    110. #include "coinwidget.h"
    111. #include "model.h"
    112.  
    113. CoinWidget::CoinWidget(QWidget *parent) : QMainWindow(parent)
    114. {
    115. SoQt::init(this);
    116. model = new Model(this);
    117. setCentralWidget(model->getWidget());
    118. model->setDefaultScene();
    119.  
    120. }
    121.  
    122. CoinWidget::~CoinWidget() {
    123. }
    124.  
    125. QSize CoinWidget::minimumSizeHint() const {
    126. return QSize(200, 200);
    127. }
    128.  
    129. QSize CoinWidget::sizeHint() const {
    130. return QSize(400, 400);
    131.  
    132. }
    133.  
    134. //==============
    135. //model.h
    136.  
    137. # define COIN_DLL
    138. # define SOQT_NOT_DLL
    139. # define SIMAGE_DLL
    140.  
    141. #ifndef MODEL_H
    142. #define MODEL_H
    143.  
    144. #include <Inventor/Qt/SoQt.h>
    145. #include <Inventor/Qt/viewers/SoQtExaminerViewer.h>
    146. #include <Inventor/nodes/SoBaseColor.h>
    147. #include <Inventor/nodes/SoCone.h>
    148. #include <Inventor/nodes/SoSeparator.h>
    149.  
    150. class Model : public SoQtExaminerViewer
    151. {
    152. public:
    153. Model( QWidget *parent = NULL,
    154. const char *name=NULL,
    155. const SbBool embed=TRUE);
    156. ~Model(void);
    157. void setDefaultScene();
    158.  
    159. private:
    160. SoSeparator *root;
    161. SoQtExaminerViewer * eviewer;
    162. SoCone *cone;
    163. SoBaseColor * col;
    164. };
    165. #endif
    166.  
    167. //==============
    168. //model.cpp
    169.  
    170. # define COIN_DLL
    171. # define SOQT_NOT_DLL
    172. # define SIMAGE_DLL
    173.  
    174. #include <model.h>
    175.  
    176. Model::Model( QWidget *parent,
    177. const char * name,
    178. const SbBool embed)
    179. : SoQtExaminerViewer( parent,
    180. name,
    181. embed,
    182. SoQtFullViewer::BUILD_ALL,
    183. SoQtViewer::BROWSER, TRUE)
    184. {
    185.  
    186. QWidget *widget = this->buildWidget(this->getParentWidget());
    187. this->setBaseWidget(widget); //comment this to see small 2nd viewer???
    188. this->show();
    189.  
    190. }
    191. // **************************
    192. Model::~Model() {
    193. delete this;
    194. root->unref();
    195. }
    196.  
    197. // **************************
    198. void Model::setDefaultScene(void) {
    199.  
    200. root = new SoSeparator;
    201. root->ref();
    202. cone = new SoCone;
    203. root->addChild(cone);
    204. setSceneGraph(root);
    205.  
    206. }
    To copy to clipboard, switch view to plain text mode 

  2. The following user says thank you to jhearon for this useful post:


  3. #2
    Join Date
    Jun 2007
    Posts
    25
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: odd double widgets

    I'm answering my own post.
    I finally figured out the answer to this problem which is in the constructor for the model.cpp class. The SoQtExaminerViewer portion below uses a protected constructor, and delaying a superclass viewer from building it's decorations is done by passing build==FALSE as the last argument of the protected constructor. You then have to explicitly trigger the building in your own constructor.

    model.cpp
    Qt Code:
    1. Model::Model( QWidget *parent,
    2. const char * name,
    3. const SbBool embed)
    4. : SoQtExaminerViewer( parent,
    5. name,
    6. embed,
    7. SoQtFullViewer::BUILD_ALL,
    8. SoQtViewer::BROWSER, FALSE)
    9.  
    10. // Explicitly triggers the construction of viewer decorations.
    11. QWidget * widget = this->buildWidget(this->getParentWidget());
    12. this->setBaseWidget(widget);
    To copy to clipboard, switch view to plain text mode 
    ...therefore with "...SoQtViewer::BROWSER, TRUE)", above, the viewer decorations were getting built twice. Yikes.
    Last edited by jhearon; 23rd February 2008 at 18:23.

  4. The following user says thank you to jhearon for this useful post:


Similar Threads

  1. Double Click Capturing
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 8th January 2011, 14:12
  2. Qt3 - Multiple transparent widgets
    By bythesea in forum Qt Programming
    Replies: 4
    Last Post: 11th September 2009, 11:24
  3. widgets behind hidden widgets not working
    By bpetty in forum Newbie
    Replies: 13
    Last Post: 7th September 2007, 20:23
  4. Replies: 11
    Last Post: 7th July 2006, 13:09
  5. Creating Widgets
    By hylke in forum Qt Programming
    Replies: 2
    Last Post: 5th February 2006, 08:37

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.