Wednesday, January 25, 2012

In Qt how to .........?

Hi friends,
If you want to create something in Qt and not sure how to create or achieve that post your problem here. Will show our best effort to help you to get your work done.

I am posting "how to dos ....." in my posts. It is advisable to check all "how to dos....." posted so far, you might be lucky :)..... 

How to manage dynamically changing GUI in Qt?

Few days back I was developing a Qt based GUI, which had multiple widgets e.g. CheckBox, PushButton, TextEdit, Labels,...... but GUI was getting changed on certain conditions and because of that GUI was looking horrible.
Qt has a wonderful feature LayoutManager (automatic adjustment of child widgets which are available in main widget.) which was creating problem for me. I tired a lot but all my solutions was failing on some conditions so finally decided to disable the Layout manager and asked for help in one of the forum but all Qt experts suggested,layout manager is one of the nicest feature in Qt, play with it. So I was looking .........and finally found something which is really cool. So I thought of sharing this to the world.

When ever you are creating some GUI in Qt using Box Layout always add addStretch() as a last Widget into your Main Layout. It will consume the extra spaces getting created due to dynamically change in child widgets of the main widget.

To learn more about Qt Layout Manager you can visit the link: http://developer.qt.nokia.com/doc/qt-4.8/layout.html 

Code should look like below,

{
     QHBoxLayout *MainLayout = new QHBoxLayout();
     MainLayout->addWidget(MyCheckBox);

     if (condition == true)
         MainLayout->addWidget(MyTextEdit);

    MainLayout->addWidget(MyLabel1);
    MainLayout->addWidget(MyLAbel2);
    MainLayout->addStretch(); // you can add stretch factor as a parameter to addStretch function.
    ......
}

Note: Please let me know your feedback to improve my effort.

Thanks......

Wednesday, January 18, 2012

Why should user use Qt?

Advantages of Qt over other languages.
  1. One of the biggest advantage that Qt has is cross platform. User need not to change a single line of code to build on different platforms.(I did not get a chance to develop something on Linux + Qt)
  2. Working in C++ gives you great control, the possibility to work with fantastic libraries like STL, Boost, etc; and your code is compiled to native binaries that will run at full speed without the need for a virtual machine.
  3. It uses system's resources to draw windows, controls so even though you will have the same code for different platforms but your application will get the native look. Which is amazing feature from user point of view.
  4. Very rich and well developed libraries. Lot of supporting tools like Qt creator, designer, etc.
  5. Last but not the least it is open source. :)
So enjoy new application development with Qt.