QLabel is a very dynamic widget. It can be use to display text (definitely), graphic and even gif animation (this can be done by calling setMovie function). But one think that I like very much is the capability to display rich text. With a markup similar to http, you can actually shown text like: "This is sample text and this is bold sample text".
Yup, you can mix up bold text with the normal text and even more.
You can check here for the supported html tag.
One of the supported html tag is <a> for hyperlink.
If you have try it, you might be wondering "How to change the color of the text?".
It took me a while to find the solution for this.
And the answer is simple, you have to code it to the tag.
If you want the text above displayed in red color, you have to set the text property of the QLabel to the following:
<a href="myref" style="color: red">This is sample text and <b>this is bold sample text</b></a>
Sunday, February 27, 2011
Monday, February 14, 2011
Nokia will dump Symbian?
The news from Nokia to support Microsoft Windows Mobile as the OS for their phone is indeed suprised many. The Nokia share tumbled more than 10% as the result.
Hmm... What will happen with Qt.
A heated discussion about this can be found on Qt Blog site here.
Even with assurance from Qt Developer, Qt user seems to be not convinced.
Is the Qt Framework life is numbered?
Hmm... What will happen with Qt.
A heated discussion about this can be found on Qt Blog site here.
Even with assurance from Qt Developer, Qt user seems to be not convinced.
Is the Qt Framework life is numbered?
Thursday, February 10, 2011
Layout
If you are familiar with Java Swing Layout Manager, Qt Framework adopt similiar concept. But in a smarter way...
Qt Layout is very dynamic and you can actually can have a Layout inside another Layout.
So virtually you can create any kind of User Interface. Yes, any kind....
There is one thing that you must take note when you are using Qt Designer. When you have, lets say 10 widget placed on a QDialog and you want to lay it vertically one after another, you might naturally select all the widget using your mouse and then select the Vertical Layout button from the toolbar.
But wait, that is wrong.... By doing this you actually create a Layout and include all the widget to layout, but (yes, there is a but here), the layout is not attached to the QDialog. And this is not what you want because resizing the QDialog have no effect to all your widget.
The correct way of doing it is to not select anything and just click on the Vertical Layout button on the toolbar. Tricky isn't it....
But once you familiar with it you will like it very very much....
Qt Layout is very dynamic and you can actually can have a Layout inside another Layout.
So virtually you can create any kind of User Interface. Yes, any kind....
There is one thing that you must take note when you are using Qt Designer. When you have, lets say 10 widget placed on a QDialog and you want to lay it vertically one after another, you might naturally select all the widget using your mouse and then select the Vertical Layout button from the toolbar.
But wait, that is wrong.... By doing this you actually create a Layout and include all the widget to layout, but (yes, there is a but here), the layout is not attached to the QDialog. And this is not what you want because resizing the QDialog have no effect to all your widget.
The correct way of doing it is to not select anything and just click on the Vertical Layout button on the toolbar. Tricky isn't it....
But once you familiar with it you will like it very very much....
Wednesday, February 9, 2011
Picture Widget on Qt Framework
If you are just into Qt Framework, you might wonder why there is no widget for Picture/Image. I have also wonder this and spent quite some time googling to find out.
Well, it turn out you can use the QLabel for this purpose. Yup the label widget for Qt. So dont waste your time googling anymore, just use the QLabel.
Well, it turn out you can use the QLabel for this purpose. Yup the label widget for Qt. So dont waste your time googling anymore, just use the QLabel.
Tuesday, February 8, 2011
Signal and Slot
The concept of Windows Message on Windows SDK was a way too complicated and too hard to program. You have to understand tons of message and some times when you take a look on documentation provided by Microsoft, you are usually not be able to start coding without the sample code. Yup, everybody depend on sample code and hey... how many of you really know what is going on... Perhaps only 1 of 100 programmer know what is really going on, the 99 of them do not really care... It's a shame, isn't it...
But don't blame the programmer, blame the people who write the documentation. With a lot of term which is hard to understand, most of the programmer might be put off and just copy and paste the sample code to get the job done.
But wait a minute, what is the relation between Windows Message and Qt Framework...
Thanks to Qt Framework, you will no longer see Windows Message. Everything will be wrapped and presented to you as Signal and Slot. So forgot about that complicated Windows Message and its documentation.
What is Signal?
If you compare it with Windows SDK, the Signal is the Windows Message. But instead of declare it as a define (eq. #define WM_ACTIVATE 0x0006), the Signal is declared as part of your class declaration. Here is the example:
For Windows Message you might write is as:
#define WM_LINK_CLICKED WM_USER | 0x01
#define WM_LINK_HOVERED WM_USER | 0x02
And for Qt, you will write it as:
class FormOne : public QDialog
{
};
As you can see, as compare to Windows Message, you no need the documentation in order to know what parameter is passed to the message LinkClicked or LinkHovered. From the above declaration we know that LinkClicked message has no parameter and Link Hovered has 1 parameter which is QString.
For Windows Message, you will usually call PostMessage or SendMessage to send the message. On Qt, you have to do the following:
emit LinkClicked();
or
emit LinkHovered("the string to pass to the message handler");
So now you really see the different from the ease of usage.
How about Slot? What is that?
The slot is the message handler. Usually if you code using Windows SDK, you will have a big switch and decide what shall we do for a specific message.
For Qt, the message handler must be declared as slot as the following:
class FormOne : public QDialog
{
And to connect the signal and the slot you have to call a QObject::connect.
Here is the example of the constructor of the class above.
FormOne(QWidget *parent) : QDialog(parent)
{
So thats all you need to do...
And you can connect the signal of one object to the slot of the other object as well, so it is not constraint to itself.
To learn more about Signal and Slot, you can visit the following link.
So enough for now...
But don't blame the programmer, blame the people who write the documentation. With a lot of term which is hard to understand, most of the programmer might be put off and just copy and paste the sample code to get the job done.
But wait a minute, what is the relation between Windows Message and Qt Framework...
Thanks to Qt Framework, you will no longer see Windows Message. Everything will be wrapped and presented to you as Signal and Slot. So forgot about that complicated Windows Message and its documentation.
What is Signal?
If you compare it with Windows SDK, the Signal is the Windows Message. But instead of declare it as a define (eq. #define WM_ACTIVATE 0x0006), the Signal is declared as part of your class declaration. Here is the example:
For Windows Message you might write is as:
#define WM_LINK_CLICKED WM_USER | 0x01
#define WM_LINK_HOVERED WM_USER | 0x02
And for Qt, you will write it as:
class FormOne : public QDialog
{
Q_OBJECT
public:
FormOne(QWidget *parent);
~FormOne();
signals:
void LinkClicked();
void LinkHovered(const QString &);
};
As you can see, as compare to Windows Message, you no need the documentation in order to know what parameter is passed to the message LinkClicked or LinkHovered. From the above declaration we know that LinkClicked message has no parameter and Link Hovered has 1 parameter which is QString.
For Windows Message, you will usually call PostMessage or SendMessage to send the message. On Qt, you have to do the following:
emit LinkClicked();
or
emit LinkHovered("the string to pass to the message handler");
So now you really see the different from the ease of usage.
How about Slot? What is that?
The slot is the message handler. Usually if you code using Windows SDK, you will have a big switch and decide what shall we do for a specific message.
For Qt, the message handler must be declared as slot as the following:
class FormOne : public QDialog
{
Q_OBJECT};
public:
FormOne(QWidget *parent);
~FormOne();
signals:
void LinkClicked();
void LinkHovered(const QString &);
private slots:
void OnLinkClicked();
void OnLinkHovered(const QString &);
And to connect the signal and the slot you have to call a QObject::connect.
Here is the example of the constructor of the class above.
FormOne(QWidget *parent) : QDialog(parent)
{
QObject::connect (}this,
SIGNAL(LinkClicked()),
this,
SLOT(OnClickClicked())
);
QObject::connect (this,
SIGNAL(LinkHovered(const QString &)),
this,
SLOT(LinkHovered(const QString &))
);
So thats all you need to do...
And you can connect the signal of one object to the slot of the other object as well, so it is not constraint to itself.
To learn more about Signal and Slot, you can visit the following link.
So enough for now...
Has been using Qt Framework for quite a while. It is very complete, good and intuitive framework. Thanks to Nokia and now you can use it under LGPL license.
If you are fancy to have skin for your application or some animation, you have to try QT Framework and the best thing of all is the cross platform capability. You code once and it is run under Windows, Mac, Linux, Windows Mobile, Symbian and some embedded OS.
The learning curve for this framework is quite short. If you are experience with C or C++, it will just take a few weeks to get used to the framework.
I will try to post some hints based on my experience.
If you are fancy to have skin for your application or some animation, you have to try QT Framework and the best thing of all is the cross platform capability. You code once and it is run under Windows, Mac, Linux, Windows Mobile, Symbian and some embedded OS.
The learning curve for this framework is quite short. If you are experience with C or C++, it will just take a few weeks to get used to the framework.
I will try to post some hints based on my experience.
Subscribe to:
Posts (Atom)