29

By liuyanghejerry

No Comments

Categories: Qt Resource

Tags: , , ,

Gaussian Blur effect for QImage

Gaussian Blur is a common effect in normal gui development. Qt provide a class, QGraphicsBlurEffect, for QWidget to this effect.
However, what about QImage?
This is the code snippet I found in \qt\src\gui\image\qpixmapfilter.cpp:

QImage blurred(const QImage& image, const QRect& rect, int radius, bool alphaOnly = false)
{
    int tab[] = { 14, 10, 8, 6, 5, 5, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2 };
    int alpha = (radius < 1)  ? 16 : (radius > 17) ? 1 : tab[radius-1];

    QImage result = image.convertToFormat(QImage::Format_ARGB32_Premultiplied);
    int r1 = rect.top();
    int r2 = rect.bottom();
    int c1 = rect.left();
    int c2 = rect.right();

    int bpl = result.bytesPerLine();
    int rgba[4];
    unsigned char* p;

    int i1 = 0;
    int i2 = 3;

    if (alphaOnly)
        i1 = i2 = (QSysInfo::ByteOrder == QSysInfo::BigEndian ? 0 : 3);

    for (int col = c1; col <= c2; col++) {
        p = result.scanLine(r1) + col * 4;
        for (int i = i1; i <= i2; i++)
            rgba[i] = p[i] << 4;

        p += bpl;
        for (int j = r1; j < r2; j++, p += bpl)
            for (int i = i1; i <= i2; i++)
                p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
    }

    for (int row = r1; row <= r2; row++) {
        p = result.scanLine(row) + c1 * 4;
        for (int i = i1; i <= i2; i++)
            rgba[i] = p[i] << 4;

        p += 4;
        for (int j = c1; j < c2; j++, p += 4)
            for (int i = i1; i <= i2; i++)
                p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
    }

    for (int col = c1; col <= c2; col++) {
        p = result.scanLine(r2) + col * 4;
        for (int i = i1; i <= i2; i++)
            rgba[i] = p[i] << 4;

        p -= bpl;
        for (int j = r1; j < r2; j++, p -= bpl)
            for (int i = i1; i <= i2; i++)
                p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
    }

    for (int row = r1; row <= r2; row++) {
        p = result.scanLine(row) + c2 * 4;
        for (int i = i1; i <= i2; i++)
            rgba[i] = p[i] << 4;

        p -= 4;
        for (int j = c1; j < c2; j++, p -= 4)
            for (int i = i1; i <= i2; i++)
                p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
    }

    return result;
}

And a demo:

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QLabel label;
    QImage image("image.png");
    image =  blurred(image,image.rect(),10,false);
    label.setPixmap(QPixmap::fromImage(image));
    label.show();

    return a.exec();
}

Nice and simple, huh?

16

By liuyanghejerry

No Comments

Categories: Qt, Qt Resource

Tags: , ,

Couples of widgets — wwWidgets

wwWidgets is a set of widgets, which can be GPL or Commercial, made by Witold Wysota:

wwWidgets is a professional set of useful widgets for Qt 4. It consists of several different widgets that are either enhanced versions of widgets bundled with Qt or completely new ones that implement functionality not available in Qt including custom multipage container widgets that can hold other widgets.

The classes follow all guidelines for building new widgets. Thanks to that they can be used with different widget styles (like Plastique or WindowsXP) and they are easily stylable using Qt style sheets allowing a perfect blend with the rest of your application.

All widgets can be used directly from within Qt Designer thanks to the widget plugin acompaniating the library. The plugin makes it possible to place wwWidgets on forms and edit their properties and contents just like for default widgets – using the property browser and dedicated property editors for complex properties like sets of colors.

wwWidgets are well documented, after installing the package, the reference is available from within Qt Assistant. The documentation looks like the one available for default Qt classes so it integrates well with it – you can browse and search the documentation and all wwWidgets component symbols can be found in the index.

Its website:http://www.wysota.eu.org/wwwidgets/

17

By liuyanghejerry

No Comments

Categories: Qt Widget

Tags: , ,

QGradualBox

QGradualBox is a widget that can show messages faded in and faded out. Using this way to notify user may be more user-friendly.

However, due to the asynchronous function setText()  while all the other settings functions are synchronous, the settings functions such as setBackgroundColor() will function immediately rather than the next setText() call.

To deal with the problem, just use the signal and slots to get the accurate opportunity the text shown down or not.

Download:QGradualBox

5

By liuyanghejerry

No Comments

Categories: About Us, Misc

Tags: ,

Git me please

I just make a new git repository at https://github.com/liuyanghejerry/Qt-Plus.

Actually it’s not my first time to use git but I was away from coding and git for a while – hopes I didn’t make any mistakes on it :)

Since it is already there, I will be glad to see if anyone can commit code with it. If you want to be a member of it, just e-mail me^^

4

By liuyanghejerry

No Comments

Categories: Qt Widget

Tags: , ,

QIPLineEdit

There’re some people searching around a perfect IP widget with mask and rx, so this is it.

This Widget can have a mask set to 000.000.000.000, and also can limit user a valid IP address.

Source Downlaod:QIPLineEdit

4

By liuyanghejerry

No Comments

Categories: Qt Widget

Tags: , ,

QIRCLineEdit

This is a IRC chat like LineEdit widget.

It uses a QList<QString> to record the history input, and works when slot myclear() was emitted.

Source Download:

QIRCLinedit