drawing lines over child widgets ?
Markus Gustavsson
mighty at fragzone.se
Thu Jun 8 17:08:49 BST 2000
Thorsten Gecks wrote:
>
> How can I draw lines in a widget over(!) its child widgets ?
>
> The answer to this question is important for my programming at all.
>
> Thanks,
>
> thorsten
>
> t_gecks at informatik.uni-kl.de
I don't think it's possible do do that kind of line drawing afaik,
however, you may be able to acheive the same result with a little
trick, although it's slower than if it could have been drawn right
through a child widget (probably not noticeable slower if you aren't
writing something which needs to move and update really fast).
#####################################################
background.h:
#ifndef BACKGROUND_H
#define BACKGROUND_H
#include <qwidget.h>
#include <qgroupbox.h>
#include <qcheckbox.h>
#include <qpixmap.h>
class Background
{
public:
Background();
~Background();
void parse(QWidget *dst, QWidget *src);
void parse(QGroupBox *dst, QWidget *src);
void parse(QCheckBox *dst, QGroupBox *src);
private:
QPixmap *map;
};
#endif
background.cpp:
#include "background.h"
Background::Background()
{
map = new QPixmap();
}
Background::~Background()
{
delete map;
}
void Background::parse(QWidget *dst, QWidget *src)
{
map->resize(dst->width(), dst->height());
bitBlt(map, 0, 0, src->backgroundPixmap(), dst->x(), dst->y(), dst->width(), dst->height());
dst->setBackgroundPixmap(*map);
}
void Background::parse(QGroupBox *dst, QWidget *src)
{
map->resize(dst->width(), dst->height());
bitBlt(map, 0, 0, src->backgroundPixmap(), dst->x(), dst->y(), dst->width(), dst->height());
dst->setBackgroundPixmap(*map);
}
void Background::parse(QCheckBox *dst, QGroupBox *src)
{
map->resize(dst->width(), dst->height());
bitBlt(map, 0, 0, src->backgroundPixmap(), dst->x(), dst->y(), dst->width(), dst->height());
dst->setBackgroundPixmap(*map);
}
#####################################################
You get the trick? Just add new rules for all widget types
you need to have copied up from the background.
Create a Background object in your class, then paint the
base widget, and recursivly call Background::parse() on all
of the childs. You might want to add these recursive parse()
calls to the mothers resizeEvent() to have it realigned each
time it's rezised by the user.
I don't know if this helps, but's it's possibility that you
might fins this usefull as a placebo for drawing real lines
through childwidgets (which I don't think can be done).
Example, http://mag.cx/~mighty/backparsed.jpg
/Markus
More information about the KDevelop
mailing list