how to use QT QProgressBar to show busy/indefinite status

A progress bar is used to give the user an indication of the progress of an operation and to reassure them that the application is still running.

The progress bar uses the concept of steps. You set it up by specifying the minimum and maximum possible step values, and it will display the percentage of steps that have been completed when you later give it the current step value.

In QT we can use QProgressBar widget which provides a horizontal or vertical progress bar for the same.

To show busy or indefinite time in progress bar using QT, just set the maximum and minimum limits of QProgressBar to 0.

QProgressBar *pbarDL;
//To start indefinite/busy progress bar
pbarDL->setMaximum(0);
pbarDL->setMinimum(0);
//To stop just set any value to maximum
pbarDL->setMaximum(10);
And you will get
QProgressBar showing Busy status

QProgressBar showing Busy status

That’s it.. Easy enough na..Winking smile

XRC – The XML Based Resource System in wxWidgets

XRC allows user interface elements such as dialogs, menu bars and toolbars, to be stored in text files and loaded into the application at run-time.

XRC files can be compiled in to two formats.
    1. XRS : To store all resources in a single file.
    2. C++ : To embed resource into executable.

Why do we use XRC

  • Resource change doesn’t need recompiling and linking.
  • Separation of resources and code.
  • You can choose between different alternative resource files at run time, if necessary.
  • The XRC format uses sizers for flexibility, allowing dialogs to be resizable and highly portable.
  • The XRC format is a wxWidgets standard, and can be generated or postprocessed by any program that understands it. As it is based on the XML standard, existing XML editors can be used for simple editing purposes.

XRC Basics

  • Include Header : wx/xrc/xmlres.h.
  • wxFileSystem archive handler is needed for XRS files. Install wxFileSystem archive handler first with wxFileSystem::AddHandler(new wxArchiveFSHandler);
  • To load resource file
    • From your wxApp::OnInit() function call wxXmlResource::Get()->InitAllHandlers()
    • Then call wxXmlResource::Get()->Load(“myfile.xrc”)
  • to create a dialog from a resource, create it using the default constructor, and then load it. For example wxXmlResource::Get()->LoadDialog(&dlg, this, "dlg1");
  • set up event tables as usual but use the XRCID(str) macro to translate from XRC string names to a suitable integer identifier, for exampleEVT_MENU(XRCID("quit"), MyFrame::OnQuit).
XRC File Creation

To create an XRC file, you can use one of the following methods.

  • Create the file by hand;
  • use wxFormBuilder, Open source designer supporting C++, Python and XRC.
  • use DialogBlocks, a commercial dialog editor;
  • use XRCed, a wxPython-based dialog editor that you can find in the wxPython/tools subdirectory of the wxWidgets CVS archive;
  • use wxGlade, a GUI designer written in wxPython. At the moment it can generate Python, C++ and XRC;
  • convert WIN32 RC files to XRC with the tool in contrib/utils/convertrc.

A complete list of third-party tools that write to XRC can be found at www.wxwidgets.org/wiki/index.php/Tools.

You can use wxXmlResource::Load in a number of ways. You can pass an XRC file (XML-based text resource file) or a zip-compressed file (extension ZIP or XRS) containing other XRC.

How to use QTabWidget

Declaration and Adding Tabs

QTabWidget MainIFaceTab = new QTabWidget(this);

MainIFaceTab->addTab(new QWidget(),”Tab1”);

MainIFaceTab->addTab(new QWidget(),”Tab2”);”

Getting widget back from a tab

QWidget *wgt = MainIFaceTab->widget(0); //Returns widget of Tab1(Index starts from 0)

Setting a widget to Tab

We need to

1. Create a layout.

2. Add the widget to be set to the layout

3. Set the layout to the returned widget from Tab.

QWidget *wgt = MainIFaceTab->widget(0); //Returns widget of Tab1(Index starts from 0)

QVBoxLayout *vBoxLay = new QVBoxLayout; //create layout

vBoxLay->addWidget(qTable); //Adds a table widget to the layout

wgt->setLayout(vBoxLay); //Set the layout with the table to the returned widget.