Results 1 to 8 of 8

Thread: DockWidget with Direct3D Widget and expanding problem

  1. #1
    Join Date
    Dec 2014
    Posts
    49
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5 PyQt3 PyQt4
    Platforms
    Windows

    Default DockWidget with Direct3D Widget and expanding problem

    I have the following setup within Qt

    Qt Code:
    1. class Editor : public QMainWindow {
    2. ...
    3. };
    To copy to clipboard, switch view to plain text mode 
    Within this Editor class, i create a SceneWidget which is defined as

    Qt Code:
    1. class EditorSceneWindow : public QDockWidget {
    2. ...
    3. };
    To copy to clipboard, switch view to plain text mode 
    Within the EditorSceneWindow i have a custom Direct3D widget defined as

    Qt Code:
    1. class D3DRenderWidget : public QWidget {
    2. ...
    3. };
    To copy to clipboard, switch view to plain text mode 

    I create an EditorSceneWindow and set it's parent to MainWindow. In EditorSceneWindow, i create a D3DRenderWidget that initializes my engine.

    My problem is that when the application starts up, the size of my Direct3DWidget is 100x30 (Toolbar dimensions of the DockWidget. I know i can set the minimum width/height, however, i want the Direct3DWidget to fill the entire DockWidget. I have tried setting numerous different combos of the QSizePolicy for the Direct3DWidget, as it is the child of the SceneWindow DockWidget.

    Thanks in advance.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: DockWidget with Direct3D Widget and expanding problem

    You probably need to put your render widget inside a layout inside the dock widget. If the render widget is the only widget in the dock widget, then either a QVBoxLayout or a QHBoxLayout will do.

    Qt Code:
    1. class EditorSceneWindow : public QDockWidget {
    2. Q_OBJECT;
    3.  
    4. EditorSceneWindow( QWidget * parent )
    5. : QDockWidget( parent )
    6. {
    7. QHBoxLayout * layout = new QHBoxLayout( this );
    8. layout->addWidget( new D3DRenderWidget( this ) );
    9. setLayout( layout );
    10. // ....
    11. }
    12. };
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: DockWidget with Direct3D Widget and expanding problem

    Did you call setWidget() on the dock widget?

    Cheers,
    _

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

    d_stranz (29th December 2014)

  5. #4
    Join Date
    Dec 2014
    Posts
    49
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5 PyQt3 PyQt4
    Platforms
    Windows

    Default Re: DockWidget with Direct3D Widget and expanding problem

    So i just created a QVBoxLayout based on the code snippet above, but still got the same results.

    EditorSceneWindow file
    Qt Code:
    1. void EditorSceneWindow::Create(WeakPtr<Engine> engine) {
    2. engine_ = engine;
    3.  
    4. QVBoxLayout* layout = new QVBoxLayout(this);
    5.  
    6. d3dRendererWidget_ = new D3DRenderWidget(this, engine_);
    7. layout->addWidget(d3dRendererWidget_);
    8.  
    9. this->setLayout(layout);
    10. }
    To copy to clipboard, switch view to plain text mode 

    D3DRenderWidget file
    Qt Code:
    1. D3DRenderWidget::D3DRenderWidget(QWidget* parent, Engine* engine) :
    2. QWidget(parent) {
    3.  
    4. setAttribute(Qt::WA_PaintOnScreen, true);
    5. setAttribute(Qt::WA_NativeWindow, true);
    6.  
    7. QSizePolicy sizePolicy = this->sizePolicy();
    8. setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
    9. }
    To copy to clipboard, switch view to plain text mode 

  6. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: DockWidget with Direct3D Widget and expanding problem

    Did you try calling QDockWidget::setWidget() as anda_skoa suggested?

    Does your render widget have an inherent size? Or do you have to set it somewhere? Presumably if you are going to use it to render something with Direct3D, you need to give it a size somewhere. What happens if you call resize( 300, 300 ) (for example) in the render widget constructor?

  7. The following user says thank you to d_stranz for this useful post:

    NIteLordz (30th December 2014)

  8. #6
    Join Date
    Dec 2014
    Posts
    49
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5 PyQt3 PyQt4
    Platforms
    Windows

    Default Re: DockWidget with Direct3D Widget and expanding problem

    Yea, i call QDockWidget::setWidget() and calling resize(300, 300) creates the display, but it does not expand vertically filling the widget. It does fill it in horizontally. I have three dock widgets, all set at the top, and when i close one of the non scene dock window, the scene dock window expands horizontally to fill the area. However, if i close the dock window that is docked on the bottom, the scene window does not fill in that additional area.

    Also, if i only use the scene dock window, no other dock windows, it is has the same outcome.

    Editor.cpp
    Qt Code:
    1. void Editor::CreateSceneDockWindow() {
    2. sceneWindow_ = new EditorSceneWindow(context_, "Scene", this);
    3. sceneWindow_->Create(engine_);
    4. addDockWidget(Qt::TopDockWidgetArea, sceneWindow_);
    5. }
    To copy to clipboard, switch view to plain text mode 

    EditorSceneWindow.cpp
    Qt Code:
    1. EditorSceneWindow::EditorSceneWindow(Context* context, QString title, QWidget* parent) :
    2. EditorWindow(context, title, parent),
    3. d3dRendererWidget_(0) {
    4. setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    5. }
    6.  
    7. EditorSceneWindow::~EditorSceneWindow() {
    8.  
    9. }
    10.  
    11. void EditorSceneWindow::Create(WeakPtr<Engine> engine) {
    12. engine_ = engine;
    13.  
    14. QWidget* container = new QWidget(this);
    15. container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    16.  
    17. QVBoxLayout* layout = new QVBoxLayout(this);
    18. d3dRendererWidget_ = new D3DRenderWidget(this, engine_);
    19. layout->addWidget(d3dRendererWidget_);
    20. container->setLayout(layout);
    21.  
    22. setWidget(container);
    23. }
    To copy to clipboard, switch view to plain text mode 

    D3DRenderWindow.cpp
    Qt Code:
    1. D3DRenderWidget::D3DRenderWidget(QWidget* parent, Engine* engine) :
    2. QWidget(parent) {
    3.  
    4. setAttribute(Qt::WA_PaintOnScreen, true);
    5. setAttribute(Qt::WA_NativeWindow, true);
    6. setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    7. resize(640, 480);
    8.  
    9. //
    10. engine_ = engine;
    11.  
    12. // Set our Direct3D widget as the window to render into
    13. Platform* platform = engine_->GetSubsystem<Platform>();
    14. platform->SetExternalWindow(reinterpret_cast<void*>(this->winId()));
    15.  
    16. // Configure the engine for Editor functionality
    17. VariantMap engineParameters;
    18. engineParameters["Fullscreen"] = false;
    19.  
    20. QTimer* timer = new QTimer(this);
    21. connect(timer, SIGNAL(timeout()), this, SLOT(update()));
    22. timer->start(16);
    23. }
    24.  
    25. D3DRenderWidget::~D3DRenderWidget() {
    26.  
    27. }
    28.  
    29. void D3DRenderWidget::paintEvent(QPaintEvent* event) {
    30. if (!engine_) return;
    31.  
    32. engine_->RunFrame();
    33. }
    34.  
    35. void D3DRenderWidget::resizeEvent(QResizeEvent* event) {
    36. int widgetWidth = width();
    37. int widgetHeight= height();
    38.  
    39. using namespace WindowResized;
    40.  
    41. VariantMap resizeEventMap;
    42. resizeEventMap[P_WIDTH] = width();
    43. resizeEventMap[P_HEIGHT] = height();
    44. engine_->SendEvent(E_WINDOWRESIZED, resizeEventMap);
    45. }
    To copy to clipboard, switch view to plain text mode 


    Added after 21 minutes:


    Issue Resolved!!!

    Found this article which states that you have to have a central widget, even if nothing is present in it. you can just hide it. one line of code, and BOOM!

    placed this inside Editor.cpp constructore, and now it fills in the area as expected.
    Qt Code:
    1. ui->centralWidget->hide();
    To copy to clipboard, switch view to plain text mode 

    Thanks much for your help!!!

    Note, as i am new on these forums, is there reputation points or anything, if so, i would give you a +1, if not, thanks anyways
    Last edited by NIteLordz; 30th December 2014 at 02:12.

  9. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: DockWidget with Direct3D Widget and expanding problem

    you have to have a central widget
    Strange side effect, but if it works, fine. So it sounds like in effect you are using dock widgets like MDI subwindows? Why not just use MDI instead? Or do you need the docking ability for some reason?

    is there reputation points or anything,
    Clicking the "Thanks" and six-pointed star buttons do that. We all appreciate it.

  10. The following user says thank you to d_stranz for this useful post:

    NIteLordz (30th December 2014)

  11. #8
    Join Date
    Dec 2014
    Posts
    49
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5 PyQt3 PyQt4
    Platforms
    Windows

    Default Re: DockWidget with Direct3D Widget and expanding problem

    I am using the dock widgets for two reasons, one being i wanted to learn about docking, and two, actually in my application i plan to have a handful of windows, and providing the undock feature seems an interesting fit. I'm the kind of coder who enjoys learning new techniques, and this is definitely one that i am learning a lot about, from concept through implementation.

    Thanks again for your help!

  12. The following user says thank you to NIteLordz for this useful post:

    d_stranz (31st December 2014)

Similar Threads

  1. Expanding custom widget
    By Raz0rEdge in forum Qt Programming
    Replies: 2
    Last Post: 14th November 2012, 14:56
  2. Direct3D widget
    By ixSci in forum Qt Programming
    Replies: 19
    Last Post: 15th October 2009, 21:40
  3. Expanding/shrinking a widget
    By punkypogo in forum Qt Programming
    Replies: 6
    Last Post: 27th May 2008, 16:50
  4. How to put a DockWidget or Widget over others??
    By dungsivn in forum Qt Programming
    Replies: 6
    Last Post: 25th October 2007, 06:12
  5. Expanding and hiding a widget
    By Dauntless in forum Newbie
    Replies: 3
    Last Post: 12th December 2006, 06:28

Tags for this Thread

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.