十二

16

By liuyanghejerry

No Comments

Categories: Qt Official

Qt 4.8 is released

Now the newest version of Qt, Qt 4.8, is released at http://labs.qt.nokia.com/2011/12/15/qt-4-8-0-released/.

The new version has been under beta for about 5 months, intros many new changes, including the new Webkit inside and a lighthouse. release note is at here, and you can download Qt 4.8 here.

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?

22

By liuyanghejerry

No Comments

Categories: Qt Official

Tags:

Qt Project is live now

The Qt Project, located at http://qt-project.org/ is live today early.

After Nokia abandoned Meego system, Qt is almost no use for it. Happily, the project is open now and Qt is like other opensource software.

10

By liuyanghejerry

No Comments

Categories: Qt Widget

Tags: , ,

AutoAdvance in QTimeEdit

AutoAdvance, is a feature that allows you step up or down in whole sections. For example, when 4:59 and you try to step up, you will get 5:00, when the feature is enabled.

This is a useful feature but disappeared since Qt 3.3. And below, is my own method to implement it.


class myTime : public QTimeEdit
{
Q_OBJECT
public:
virtual void stepBy(int steps)
{
if (this->time().minute()==59 && steps>0){
setTime(QTime(time().hour()+1,0,time().second(),time().msec()));
}else if(this->time().minute()==00 && steps<0){
setTime(QTime(time().hour()-1,59,time().second(),time().msec()));
}else{
QTimeEdit::stepBy(steps);
}
}
};

Keep in mind, to enable the code beyond, must setWrapping(true).

7

By liuyanghejerry

No Comments

Categories: Qt, Qt Resource

Tags: , ,

How to draw glow text using QPainter

Searching around, there’s no good way for a font filter when using QFont. Since QPainter still usable for us, we could use QPainter to draw text looks like glow.

Glow text can be treated as “text beyond text”, which means:

More layers, more glow we look like. The code can be seems like below:

void GlowTicker::paintEvent(QPaintEvent *)
{
QPainter painter(this);

painter.setOpacity(0.5);
painter.setPen(_glowColor);
painter.drawText(QRect(QPoint(1 – _offset, 2), textSize()), Qt::TextSingleLine, _text);
painter.drawText(QRect(QPoint(3 – _offset, 2), textSize()), Qt::TextSingleLine, _text);
painter.drawText(QRect(QPoint(2 – _offset, 1), textSize()), Qt::TextSingleLine, _text);
painter.drawText(QRect(QPoint(2 – _offset, 3), textSize()), Qt::TextSingleLine, _text);

int w = preferedWidth();
painter.drawText(QRect(QPoint(1 + w – _offset, 2), textSize()), Qt::TextSingleLine, _text);
painter.drawText(QRect(QPoint(3 + w – _offset, 2), textSize()), Qt::TextSingleLine, _text);
painter.drawText(QRect(QPoint(2 + w – _offset, 1), textSize()), Qt::TextSingleLine, _text);
painter.drawText(QRect(QPoint(2 + w – _offset, 3), textSize()), Qt::TextSingleLine, _text);

painter.setOpacity(1);
painter.setPen(_textColor);
painter.drawText(QRect(QPoint(2 – _offset, 2), textSize()), Qt::TextSingleLine, _text);
painter.drawText(QRect(QPoint(2 + w – _offset, 2), textSize()), Qt::TextSingleLine, _text);
}

For the layers, we need them transparent or it will influence the main layer.
Well, last show:

<a href="http://qtplus.info/wp-content/uploads/2011/08/glow-text1.png"><img class="alignnone size-full wp-image-74" title="glow text" src="http://qtplus.info/wp-content/uploads/2011/08/glow-text1.png" alt="" width="234" height="64" /></a>

25

By liuyanghejerry

No Comments

Categories: Qt Resource

Tags: ,

Two Inspectors for Qt

I just found two great tools for Qt. They’re Qt Inspector and basyskom Inspector.

These two inspectors are just like the Web Inspector of Webkit or the Firebug of FireFox. You can use them view or edit a Qt-based program without recompile, like shown below:

inspector-dolphin-settings

Qt Inspector worked with Dolphin

Without more test, I’m not sure if these two tools can work on Windows or only on KDE. If you’re interested in them and would like give them a whirl, tell me your results.

24

By liuyanghejerry

No Comments

Categories: Qt Official

Tags: ,

Qt 4.8 Beta is coming

Few days ago, Qt labs post a new article that says Qt 4.8 beta is released. This is the first beta of Qt 4.8 and includes the main features below:

  • Lighthouse, a clean abstraction layer for porting Qt to new GUI platforms
  • Threaded OpenGL support
  • Multithreaded HTTP
  • Optimized file system access
  • Native Symbian networking, Ipv6 and OpenGL Graphics, Symbian resource management
  • New localisation and IP multicast APIs
  • Right-to-left text support, on-screen keyboard support and improved image caching in Qt Quick
Noticed that the lighthouse is included so that it may help porting Qt onto new devices like smart phones.
Now, the source code can be download either with .zip or with .tar.gz, and the checksum.txt is also available here.

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/

27

By liuyanghejerry

No Comments

Categories: Qt, Qt Resource

Tags: ,

QtOgreFramework

While looking around, I found a framework combines Ogre with Qt. Ogre is a well-known open-source 3D graphic engine, that brings impressive effects. The framework supports…

  • A configuration dialog:
    • Contains a ‘Graphics configuration widget’ to configure Ogre.
    • Support for rendering systems, resolution, etc.
    • All config settings stored to an .ini file
  • A log viewer:
    • Syntax highlighting and filtering
    • Qt’s message handler are redirected to this system
    • Ogre’s logs are also redirected
  • A Frames Per Second widget
    • Actaully a Qt Dialog
    • Window decorations turned off
    • Custom mouse handling so it can be dragged around
  • Simple to use interface:
    • Just inherit from ‘GameLogic’ class and override the desired functions
    • Demo is included which shows basic usage
    • Very few assumptions made so you have maximum flexibility
  • Support for transparent windows on some systems (Vista, Linux with Compviz)

As above, it may help if you want make a game with both Qt and Ogre. Unluckily, it seems not been developed since Aug, 2010 :(

Links:

http://www.ogre3d.org/forums/viewtopic.php?f=11&t=45709
https://ogreaddons.svn.sourceforge.net/svnroot/ogreaddons/trunk/QtOgreFramework/

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

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