?
Solved

qt opengl QGLWidget inside QMainWindow

Posted on 2006-03-23
5
Medium Priority
?
3,157 Views
Last Modified: 2013-11-23
Hi, im doing some qt opengl programming in windows.

I need a window split in 2 pieces (right one must be an opengl window), with a top menu (file edit view favorites tools help thingy). In order to make the top menu there is a class that is derived from QMainWindow.

Question: How do I get a qt window that is split into 2 sections, with a top menu?

code I left off, its the opengl window that isn't willing to appear on screen:

MainWindow::MainWindow(QWidget *parent ,const char *name ) : QMainWindow(parent, name)
{
      createActions();
      createMenus();
      createToolbars();
      // no status bar


      
      // some frames
      QFrame* f1 = new QFrame( this, "frame1" );
      QFrame* f2 = new QFrame( this, "frame2" );
      QFrame* f3 = new QFrame( this, "frame3" );

    // Widget creation
      //createProgressBar();
      //createGLWidget();
      
      glWidget = new CGLWidget(f1, "glWidget");

      //createPanel();
      //QVBoxLayout *leftLayout = new QVBoxLayout;
      //QVBoxLayout *bottomRightLayout = new QVBoxLayout;
      //bottomRightLayout->addWidget(timeProgressBar);
      //      QVBoxLayout *rightLayout = new QVBoxLayout;
      //      rightLayout->addWidget(glWidget);
      //      rightLayout->addLayout(bottomRightLayout);
      QHBoxLayout *mainLayout = new QHBoxLayout(f1, 2, 2, "flayout1");
      mainLayout->addWidget(glWidget);

      
   

    //QHBoxLayout* flayout1 = new QHBoxLayout( f1, 2, 2, "flayout1");
    //flayout1->addWidget( GLView );
}

thanks in advance.
0
Comment
Question by:DaFou
  • 3
  • 2
5 Comments
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 16277071
You mean you want two top level windows ?
0
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 16277088
If you want the GL window to be top level then
Do something like this

QFrame* f1 = new QFrame( 0, "frame1" ); // 0 removed with this
...
glWidget = new CGLWidget(f1, "glWidget");
...
0
 
LVL 2

Author Comment

by:DaFou
ID: 16278699
No, i want to see a window derived from the QMainWindow class, splitted horizontal in two pieces and with the right one viewing opengl.

some header code for clarification:
#include <stdio.h> // printf
#include <qapplication.h>
#include "mainwindow.h"

int main(int argc, char* argv[])
{
      QApplication app(argc, argv);
      if(!QGLFormat::hasOpenGL())
            qFatal("This system has no OpenGL support.");
      MainWindow theWindow;
      app.setMainWidget(&theWindow);
      theWindow.show();
      return app.exec();
}



#if !defined(AFX_GLWIDGET_H__EED2A780_631B_438F_9B09_3F0E27084BBF__INCLUDED_)
#define AFX_GLWIDGET_H__EED2A780_631B_438F_9B09_3F0E27084BBF__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


#include <qgl.h>

#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glut.h>

class CGLWidget : public QGLWidget  
{
public:
      CGLWidget(QWidget *parent = 0, const char * name = 0);
      virtual ~CGLWidget();

protected:
      void draw();
      void resizeGL(int width, int height);
      void initializeGL();
      void paintGL();
};

#endif // !defined(AFX_GLWIDGET_H__EED2A780_631B_438F_9B09_3F0E27084BBF__INCLUDED_)


#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "glwidget.h"

#include <qmainwindow.h>#include <qlabel.h>#bla blayout.h>

class MainWindow : public QMainWindow  
{

      Q_OBJECT
public:
      MainWindow(QWidget *parent = 0,const char *name = 0);
      virtual ~MainWindow();

private:
      bool modified;
      bool maybeSave();
      protected:
            void closeEvent(QCloseEvent *event);
            void contextMenuEvent(QContextMenuEvent *event);
      private slots:
            void newFile();
            void open();
            bool save();
            //bool saveAs();
            void about();
      private:
            void createProgressBar();
      // actions
      void createActions();
      QAction *newAct;
      QAction *openAct;
      //
      QAction *aboutAct;
      
      // menus
      void createMenus();
      QPopupMenu *fileMenu;
      QPopupMenu *editMenu;
      QPopupMenu *toolsMenu;
      QPopupMenu *aboutMenu;
            
      // progress bar
      QProgressBar *timeProgressBar;

      // timer
            int myTimerId;
      protected:
      void timerEvent(QTimerEvent *event);
      // toolbars
      void createToolbars();
      QToolBar *fileToolBar;
      QToolBar *editToolBar;
      QToolBar *toolsToolBar;
      QToolBar *helpToolBar;

      // save dialog
      void MaybeSave();

      // widgets
      CGLWidget *glWidget;
};

#endif // !defined(AFX_MAINWINDOW_H__F0827899_A2E2_4FE1_8E41_F9E0333F3B2F__INCLUDED_)
0
 
LVL 12

Accepted Solution

by:
rajeev_devin earned 2000 total points
ID: 16280246
Hi DaFou
I got the thing.
Are you using Qt4 or Qt3 ? From your code it seemd you are using Qt3.

You need to use two QDockWidget that will split your main window into two regions.
In Qt3 may be it is called QDockWindow. Just check this out.

Please mail again if you fase any problem.
0
 
LVL 2

Author Comment

by:DaFou
ID: 16296612
QDockWindow works also but I have chosen to use the splitter. Thank you for your information on the domain of Qt3 I have used it to work out all posibilities.


// splitter
      horSplitter = new QSplitter(Horizontal, this);
      setCentralWidget(horSplitter);
      
// widgets
      leftWidget = new CLeftWidget(horSplitter);
      glWidget = new CGLWidget(horSplitter);

DaFou
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question