qt-interest@trolltech.com
[Top] [All Lists]

Re: how to change the layout spacing fill color

Subject: Re: how to change the layout spacing fill color
From: Paul Koshevoy
Date: Sun, 30 Apr 2006 14:57:26 -0600
Dimitri wrote:
Hi,

I've attached a minimal example [...]

Is this really a minimal example? I mean, do you need both the main window and the tab widget to reproduce the problem?

--
Dimitri

I just tried building an even smaller example, and I can't
reproduce the problem there. I've put it in the attachment.

What could this mean? Am I doing something wrong with the tab widget?

        Paul.
TEMPLATE        = app
LANGUAGE        = C++
TARGET          = minimal-minimal
PROJECTNAME     = minimal-minimal

QT += opengl

CONFIG  += qt rtti exceptions opengl warn_on debug thread console

SOURCES += the_main.cxx

DEPENDPATH      = ./

UI_DIR = ui
MOC_DIR = moc
OBJECTS_DIR = obj
// system includes:
#include <iostream>

// Qt includes:
#include <QApplication>
#include <QWidget>
#include <QGLWidget>
#include <QGridLayout>

// namespace access:
using std::cout;
using std::cerr;
using std::endl;

// FIXME:
static const QColor bg_color(0x55, 0xaf, 0x7f);
static const QColor fg_color(0xe2, 0xef, 0xba);


//----------------------------------------------------------------
// the_view_t
// 
class the_view_t : public QGLWidget
{
public:
  the_view_t(QWidget * parent, const char * name, QGLWidget * shared = NULL):
    QGLWidget(parent, shared, 0)
  {
    setObjectName(name);
    if (shared == NULL) setFocus();
    
    setAttribute(Qt::WA_NoBackground);
    setFocusPolicy(Qt::StrongFocus);
    setMouseTracking(true);
  }
  
protected:
  // virtual: QT/OpenGL stuff:
  void paintGL()
  {
    glDisable(GL_LIGHTING);
    glDisable(GL_DEPTH_TEST);
    
    // draw the background:
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    
    glViewport(0, 0, width(), height());
    
    glMatrixMode(GL_PROJECTION);
    gluOrtho2D(0.0, 1.0, 0.0, 1.0);
    
    glBegin(GL_QUADS);
    {
      glColor3ub(fg_color.red(), fg_color.green(), fg_color.blue());
      glVertex2f(0.0, 1.0);
      glVertex2f(1.0, 1.0);
      glVertex2f(1.0, 0.0);
      glVertex2f(0.0, 0.0);
    }
    glEnd();
  }
};


//----------------------------------------------------------------
// main
// 
int
main(int argc, char ** argv)
{
  // this is so that the printouts look better:
  std::cout.precision(8);
  std::cout.setf(std::ios::scientific);
  
  // parse command line for input/output trail file options:
  QApplication A(argc, argv);
  
  QWidget main_window;
 
  // setup background color:
  QPalette palette = main_window.palette();
  palette.setColor(QPalette::Window, bg_color);
  main_window.setPalette(palette);
  main_window.setBackgroundRole(QPalette::Window);
  
  QGridLayout * layout = new QGridLayout(&main_window);
  layout->setSpacing(10);
  layout->setMargin(0);
  
  the_view_t * view[4];
  // setup the views:
  static const char * view_names[] = {
    "Top view",
    "Isometric view",
    "Front view",
    "Left view"
  };
  
  for (unsigned int i = 0; i < 4; i++)
  {
    view[i] = new the_view_t(NULL, view_names[i], NULL);
  }
  
  layout->addWidget(view[0], 0, 0); // top
  layout->addWidget(view[1], 0, 1); // isometric
  layout->addWidget(view[2], 1, 0); // front
  layout->addWidget(view[3], 1, 1); // left
  
  for (unsigned int i = 0; i < 4; i++)
  {
    view[i]->show();
  }
  
  main_window.resize(512, 384);
  main_window.show();
  
  // start the event loop:
  int result = A.exec();
  return result;
}
<Prev in Thread] Current Thread [Next in Thread>