medved6
5th October 2010, 06:14
Hi Everybody
I have a graphics scene and I need to have some controls on top of it( like buttons ).
This buttons should be static/unmoved while scene scaled, moved, rotated and so on.
So it seems I can not use any kind of graphicitems.
So I decided to create subclass of QWidget
#include <QPixmap>
#include <QGLWidget>
class CLStaticImageWidget : public QGLWidget
{
Q_OBJECT
public:
CLStaticImageWidget(QWidget *parent, QString img, QString name, int max_width);
signals:
void onPressed(QString name);
protected:
void paintEvent(QPaintEvent *event);
protected:
QPixmap m_img;
QString m_name;
int m_width;
int m_height;
};
and cpp file
CLStaticImageWidget::CLStaticImageWidget(QWidget *parent, QString img, QString name, int max_width):
QGLWidget(parent,0)//, Qt::Window)
{
hide();
m_img = cached(img);
int w = m_img.width();
int h = m_img.height();
qreal apect = (qreal)w/h;
m_width = max_width;
m_height = max_width/apect;
QSize size(m_width, m_height);
setMaximumSize(size);
setMinimumSize(size);
setWindowOpacity(0.5); // here is an issue
}
void CLStaticImageWidget::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.drawPixmap(QRect(0,0,m_width,m_height), m_img, m_img.rect());
painter.end();
}
and I add it to the scene inside my graphicsview like this
CLStaticImageWidget * wgt = new CLStaticImageWidget(this, "./skin/home.bmp", "home", 100);
wgt->move(1,1);
wgt->show();
So, it works fine except two issues
1) setWindowOpacity does not work. But if widget has flag Qt::Window it works.
Is there any way I can make widget transperent and do not have this Qt::Window flag.
2) If i replace QWidget with QGLWidget and add widget it first dwaws some garbage for a moment(may be something look like part of my desctop or so) and after that works fine.
Any ideas?
Thank you!
I have a graphics scene and I need to have some controls on top of it( like buttons ).
This buttons should be static/unmoved while scene scaled, moved, rotated and so on.
So it seems I can not use any kind of graphicitems.
So I decided to create subclass of QWidget
#include <QPixmap>
#include <QGLWidget>
class CLStaticImageWidget : public QGLWidget
{
Q_OBJECT
public:
CLStaticImageWidget(QWidget *parent, QString img, QString name, int max_width);
signals:
void onPressed(QString name);
protected:
void paintEvent(QPaintEvent *event);
protected:
QPixmap m_img;
QString m_name;
int m_width;
int m_height;
};
and cpp file
CLStaticImageWidget::CLStaticImageWidget(QWidget *parent, QString img, QString name, int max_width):
QGLWidget(parent,0)//, Qt::Window)
{
hide();
m_img = cached(img);
int w = m_img.width();
int h = m_img.height();
qreal apect = (qreal)w/h;
m_width = max_width;
m_height = max_width/apect;
QSize size(m_width, m_height);
setMaximumSize(size);
setMinimumSize(size);
setWindowOpacity(0.5); // here is an issue
}
void CLStaticImageWidget::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.drawPixmap(QRect(0,0,m_width,m_height), m_img, m_img.rect());
painter.end();
}
and I add it to the scene inside my graphicsview like this
CLStaticImageWidget * wgt = new CLStaticImageWidget(this, "./skin/home.bmp", "home", 100);
wgt->move(1,1);
wgt->show();
So, it works fine except two issues
1) setWindowOpacity does not work. But if widget has flag Qt::Window it works.
Is there any way I can make widget transperent and do not have this Qt::Window flag.
2) If i replace QWidget with QGLWidget and add widget it first dwaws some garbage for a moment(may be something look like part of my desctop or so) and after that works fine.
Any ideas?
Thank you!