делаю все как в тут в итоге виджет отображается либо так:
Нажмите для просмотра прикрепленного файла
либо так:
Нажмите для просмотра прикрепленного файла
при чем отчего зависит не могу разобраться.
тут исходник
/*
* controllTacticWindow.h
*/
#ifndef _CONTROLLTACTICWINDOW_H_
#define _CONTROLLTACTICWINDOW_H_
#include <QtGui>
namespace TacticalConditions {
class ControlTacticalWindow : public QWidget {
Q_OBJECT
public:
ControlTacticalWindow();
};
}
#endif// _CONTROLLTACTICWINDOW_H_
/*
* controllTacticWindow.cpp
*/
#include "controltacticalwindow.h"
namespace TacticalConditions {
ControlTacticalWindow::ControlTacticalWindow() : QWidget(0, Qt::CustomizeWindowHint | Qt::WindowTitleHint) {
setWindowTitle(tr("Items (double click to flip)"));
setWindowOpacity(0.8);
QVBoxLayout *layout = new QVBoxLayout;
setLayout(layout);
QPushButton *button;
button = new QPushButton(QIcon(QString::fromUtf8(":/images/images/up.png")), tr(""));
layout->addWidget(button);
button = new QPushButton(tr("Add circle"));
layout->addWidget(button);
button = new QPushButton(tr("Add square"));
layout->addWidget(button);
layout->addStretch(1);
}
}
TacticalWindow::TacticalWindow(QWidget * parent) : QGraphicsView(parent) {
setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
OpenGLScene *scene = new OpenGLScene;
setScene(scene);
scene->addWidget(new ControlTacticalWindow());
......
void OpenGLScene::drawBackground(QPainter *painter, const QRectF &) {
if (painter->paintEngine()->type()
!= QPaintEngine::OpenGL) {
qWarning("OpenGLScene: drawBackground needs a "
"QGLWidget to be set as viewport on the "
"graphics view");
return;
}
glDrawPixels(m_image.width(), m_image.height(), GL_RGBA, GL_UNSIGNED_BYTE, m_image.bits());
}