PDA

View Full Version : Brush problems in GraphicsView



maverick_pol
8th August 2008, 15:16
Hi guys,

I will try to be brief and concise:
I fill polygon in the scene background with Qt::DensexPattern;
My scene is a rect - > QRectF(QPOintF(-180,-90),QPointF(180,90));
When I scale to see my small area(polygon) so that only 2x2 degrees there is a border scale over which the brush disappears; I zoom out -> the brush is visible;

Maybe you had the same behaviour?

Do you have any idea how to solve it? Maybe it is a Qt bug?
I am using qt-4.4.0;

To be precise I am using an image create from a bit table, and set my brush to fill polygon with that pixmap(image);
All in all, the outcome is the same as with Qt::DensexPattern's;

Beforehand thank you for any ideas.

Kacper

maverick_pol
11th August 2008, 08:52
Maybe someone tested this "brush problem"?

Kacper

kghose
11th August 2008, 19:41
This isn't a stippling issue is it, where a shade is created by a certain density of pixels, and when you zoom in enough, you start to miss the pixels? -K

maverick_pol
11th August 2008, 20:40
Hi,

Maybe your ideas are good clues; I have a 2 dim array and have to select one of subarrays and use it as a fill pattern(brush pattern);
I am doing it this way, I am not sure is it ok.

I WOULD REALLY APPRECIATE ANY HELP.

I am pasting a bit of code, to help you to help me : )


static const char stipple_bits[12][8] =
{
{ 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF },
{ 0x0018, 0x0018, 0x0018, 0x00FF, 0x00FF, 0x0018, 0x0018, 0x0018 },
{ 0x0049, 0x0092, 0x0024, 0x0049, 0x0092, 0x0024, 0x0049, 0x0092 },
{ 0x0000, 0x003c, 0x007e, 0x0066, 0x0066, 0x007e, 0x003c, 0x0000 },
{ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 },
{ 0x00aa, 0x0055, 0x00aa, 0x0055, 0x00aa, 0x0055, 0x00aa, 0x0055 },
{ 0x0089, 0x0044, 0x0010, 0x0022, 0x0094, 0x0002, 0x0068, 0x0001 },
{ 0x0088, 0x0088, 0x0011, 0x0011, 0x0044, 0x0044, 0x0022, 0x0022 },
{ 0x003c, 0x0042, 0x00a5, 0x00a5, 0x0081, 0x00bd, 0x0042, 0x003c },
{ 0x0038, 0x0038, 0x0038, 0x0092, 0x007c, 0x0010, 0x0028, 0x006c },
{ 0x0054, 0x0029, 0x0084, 0x0029, 0x0080, 0x000c, 0x00a4, 0x0040 },
{ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 }
};

unsigned int fill_style = 2;
/*! Creating the appropriate pattern*/
QByteArray patternFillArray;
patternFillArray.fromRawData(stipple_bits[fill_style],8);


QImage image(QSize(8,8),QImage::Format_MonoLSB);
image.loadFromData(patternFillArray);
image.setColor(0,Qt::transparent);

...

and sth like:
image.setColor(1,Qt::red);/*!< Lets use RED color as fill color*/
..
painter->setBrush(QBrush(image));
painter->drawPOlygon(...);
.....

THANK YOU,

Kacper

kghose
11th August 2008, 23:12
Well, as far as I see it, its merely a fact that your brush is not a vector brush but a bitmap. So at some point you end up seeing large pixels. I'm attaching the code I used below. Why excactly do you need to zoom in so close, and what kind of behavior are you expecting from this tiled bitmap? -K


#include <iostream>
#include <QtGui>

const char stipple_bits[12][8] =
{
{ 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF },
{ 0x0018, 0x0018, 0x0018, 0x00FF, 0x00FF, 0x0018, 0x0018, 0x0018 },
{ 0x0049, 0x0092, 0x0024, 0x0049, 0x0092, 0x0024, 0x0049, 0x0092 },
{ 0x0000, 0x003c, 0x007e, 0x0066, 0x0066, 0x007e, 0x003c, 0x0000 },
{ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 },
{ 0x00aa, 0x0055, 0x00aa, 0x0055, 0x00aa, 0x0055, 0x00aa, 0x0055 },
{ 0x0089, 0x0044, 0x0010, 0x0022, 0x0094, 0x0002, 0x0068, 0x0001 },
{ 0x0088, 0x0088, 0x0011, 0x0011, 0x0044, 0x0044, 0x0022, 0x0022 },
{ 0x003c, 0x0042, 0x00a5, 0x00a5, 0x0081, 0x00bd, 0x0042, 0x003c },
{ 0x0038, 0x0038, 0x0038, 0x0092, 0x007c, 0x0010, 0x0028, 0x006c },
{ 0x0054, 0x0029, 0x0084, 0x0029, 0x0080, 0x000c, 0x00a4, 0x0040 },
{ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 }
};

class PaintMe : public QWidget
{
qreal scalex, scaley;

public:
PaintMe(QWidget *parent = 0);
void mousePressEvent (QMouseEvent *);

protected:
void paintEvent(QPaintEvent *event);

};

PaintMe::PaintMe(QWidget *parent)
: QWidget(parent)
{
setPalette(QPalette(QColor(250, 250, 200)));
setAutoFillBackground(true);
scalex = 1.0;
scaley = 1.0;
}

void PaintMe::paintEvent(QPaintEvent * /* event */)
{
unsigned int fill_style = 2;
/*! Creating the appropriate pattern*/
QByteArray patternFillArray;
patternFillArray.fromRawData(stipple_bits[fill_style],8);
QImage image(QSize(8,8),QImage::Format_MonoLSB);
image.loadFromData(patternFillArray);
image.setColor(1,Qt::red);

QPainter painter(this);
painter.scale(scalex, scaley);
painter.setBrush(QBrush(image));
QRectF rectangle(0.0, 0.0, 500.0, 500.0);
painter.drawRect(rectangle);
}

void PaintMe::mousePressEvent (QMouseEvent *event) {
switch(event->button()) {
case Qt::LeftButton:
scalex *= .7;
scaley *= .7;
std::cout << "Zoom out" << std::endl;
break;
case Qt::RightButton:
scalex *= 1.2;
scaley *= 1.2;
std::cout << "Zoom in" << std::endl;
break;
}
update();
}

class Window : public QWidget
{
public:
Window(QWidget *parent = 0);
};

Window::Window(QWidget *parent)
: QWidget(parent)
{
PaintMe *pm = new PaintMe(this);
pm->setGeometry(10, 10, 480, 480);
pm->show();
}

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Window window;
window.setGeometry(100, 100, 500, 500);
window.show();
return app.exec();
}

maverick_pol
12th August 2008, 07:38
Hi,

My scene show the whole world map. When the user wants to read detailed info about particular part he/she chooses to read data and draw them; because the areas for which I load details are very small I need to scale to see the small part on the whole screen;
Lets say that and anchorage area should be drawn using some kind of a brush, the brush is the one we are talking about.

I will check the code you have pasted.
I do not see pixels. Simply, at some point the brush disappears. I do not see larger pixels, but after zooming in few times everything is ok(brush is the same) and suddenly no brush is drawn over some scale.

Kacper

maverick_pol
12th August 2008, 09:56
Here is a sample of drawing, I need to achieve.
There is a part of an island with some black lines and "stipple fill" brown parts.
The "stipple fill" do not change while scaling.


Kacper

kghose
12th August 2008, 14:29
Hi Maverick,

The way I can think of doing what you want is to scale not the scene, but your own coordinates. So, if you have a polygon representing, say, Texas. Instead of doing "scale" in painter, you should scale the polygon coordinates yourself and then draw as usual. That way, regardless of the zoom level your stippling brush will have the same pixellation level.

-K

maverick_pol
12th August 2008, 19:25
Hi,

Yes that sounds ok, and have thought about this some time ago. For the time being I can't do that as 80% of the code is based on scene scaling. Still I need to find a solution to use the stipple brush.

Kacper