hi high_flyer ;
I found something when i was digging to google :
00090 if (myRubberBand)
00091 {
00092 // If you don't set a style, QRubberBand doesn't work properly
00093 // take these lines out if you don't believe me.
00094 // QStyle* ps = (QStyle*) new QutlProxyStyle("Plastique");
00096 myRubberBand->setStyle( ps );
00097 }
myRubberBand = new QRubberBand( QRubberBand::Rectangle, this );
00090 if (myRubberBand)
00091 {
00092 // If you don't set a style, QRubberBand doesn't work properly
00093 // take these lines out if you don't believe me.
00094 // QStyle* ps = (QStyle*) new QutlProxyStyle("Plastique");
00095 QStyle* ps = (QStyle*) new QPlastiqueStyle();
00096 myRubberBand->setStyle( ps );
00097 }
To copy to clipboard, switch view to plain text mode
many people have same problem with QGLWidget so there is a solution who claim that but it's not workinf still :s
Added after 5 minutes:
So i made a simple test project i send fully code what i've done ;
#ifndef HSGLWIDGET_H
#define HSGLWIDGET_H
#include <QtOpenGL/QGLWidget>
#include <QMouseEvent>
#include <QRubberBand>
#include <QPoint>
{
public:
}
{
Q_UNUSED(event);
pen.setWidth(5);
pen.setStyle(Qt::DashLine);
painter.begin(this);
painter.setPen(pen);
painter.setOpacity(0.5);
painter.setBrush(brush);
painter.drawRect(event->rect());
painter.end();
}
};
{
Q_OBJECT
public:
private:
CustomRB *rubberBand;
protected:
void initializeGL();
void resizeGL(int w, int h);
//void paintGL();
};
#endif // HSGLWIDGET_H
#include "hsglwidget.h"
HSGLWidget
::HSGLWidget(QWidget *parent
){
rubberBand
= new CustomRB
(QRubberBand::Rectangle,
this);
}
void HSGLWidget::initializeGL()
{
}
void HSGLWidget::resizeGL( int w, int h )
{
}
{
origin = e->pos();
rubberBand->setUpdatesEnabled(true);
rubberBand->show();
}
{
rubberBand
->setGeometry
(QRect(origin, e
->pos
()).
normalized());
}
void HSGLWidget
::keyPressEvent( QKeyEvent *e
) {
}
{
rubberBand
->setGeometry
(QRect(origin, e
->pos
()).
normalized());
rubberBand->show();
}
#ifndef HSGLWIDGET_H
#define HSGLWIDGET_H
#include <QtOpenGL/QGLWidget>
#include <QMouseEvent>
#include <QRubberBand>
#include <QPoint>
class CustomRB : public QRubberBand
{
public:
CustomRB(Shape s, QWidget *parent) : QRubberBand(s,parent) {
}
void paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
QPainter painter;
QPen pen = QPen(Qt::yellow);
pen.setWidth(5);
pen.setStyle(Qt::DashLine);
QBrush brush = QBrush(Qt::red);
painter.begin(this);
painter.setPen(pen);
painter.setOpacity(0.5);
painter.setBrush(brush);
painter.drawRect(event->rect());
painter.end();
}
};
class HSGLWidget : public QGLWidget
{
Q_OBJECT
public:
HSGLWidget(QWidget *parent = 0);
private:
CustomRB *rubberBand;
QPoint origin;
protected:
void initializeGL();
void resizeGL(int w, int h);
//void paintGL();
void mousePressEvent(QMouseEvent *e);
void mouseMoveEvent(QMouseEvent *e);
void mouseReleaseEvent(QMouseEvent *e);
void keyPressEvent(QKeyEvent *e);
};
#endif // HSGLWIDGET_H
#include "hsglwidget.h"
HSGLWidget::HSGLWidget(QWidget *parent)
:QGLWidget(parent),rubberBand(0)
{
rubberBand = new CustomRB(QRubberBand::Rectangle, this);
}
void HSGLWidget::initializeGL()
{
}
void HSGLWidget::resizeGL( int w, int h )
{
}
void HSGLWidget::mousePressEvent( QMouseEvent *e )
{
origin = e->pos();
rubberBand->setUpdatesEnabled(true);
rubberBand->setGeometry(QRect(origin, QSize()));
rubberBand->show();
}
void HSGLWidget::mouseMoveEvent( QMouseEvent *e )
{
rubberBand->setGeometry(QRect(origin, e->pos()).normalized());
}
void HSGLWidget::keyPressEvent( QKeyEvent *e )
{
}
void HSGLWidget::mouseReleaseEvent(QMouseEvent *e)
{
rubberBand->setGeometry(QRect(origin, e->pos()).normalized());
rubberBand->show();
}
To copy to clipboard, switch view to plain text mode
I promote to Widget in qtcreator with hsglwidget so it's not working properly ...
Bookmarks