十二
16
Plus Your Qt
十二
16
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
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
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.
八
7
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
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:
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
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:
六
16
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
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/
四
5
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^^
四
5
I’m thinking of using a distributed revision control system to manage all the codes of QtPlus, which is git.
There’re many reasons for using git, for example I won’t easily lose the codes like before. More than that, people can also correct or improve the codes with me.
So…Gitorious or GitHub? I’m hesitating. But soon I’ll make a decision on this:)
四
4
Well, after about few months absent, I’m glad to say, “Qt Plus is back”. And we’re using wordpress this time. Cheers^^
However, not everything seems glad.
To be honest, I just moved Qt Plus to a new server which is a bit slower than before. If you’re in China, this is more obvious. By the way, the old data is missing due to some reasons, which means we have to start with no data and no speed.
Sounds awful? Maybe a little bit…
BUT AT LEAST — WE’RE BACK.