Qt UI loader : QUiLoader « Qt « C++






Qt UI loader

  

/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial Usage
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
** $QT_END_LICENSE$
**
****************************************************************************/

#ifndef MYWIDGET_H
#define MYWIDGET_H

#include <QWidget>

class MyWidget : public QWidget
{
public:
    MyWidget(QWidget *parent = 0);
};

#endif






#include <QtGui>
#include <QtUiTools>

#include "mywidget.h"


MyWidget::MyWidget(QWidget *parent)
    : QWidget(parent)
{
    QUiLoader loader;
    QFile file(":/forms/myform.ui");
    file.open(QFile::ReadOnly);
    QWidget *myWidget = loader.load(&file, this);
    file.close();

    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(myWidget);
    setLayout(layout);
}







<ui version="4.0" >
 <author></author>
 <comment></comment>
 <exportmacro></exportmacro>
 <class>Form</class>
 <widget class="QWidget" name="Form" >
  <property name="geometry" >
   <rect>
    <x>0</x>
    <y>0</y>
    <width>258</width>
    <height>224</height>
   </rect>
  </property>
  <property name="windowTitle" >
   <string>Export Document</string>
  </property>
  <layout class="QVBoxLayout" >
   <property name="margin" >
    <number>8</number>
   </property>
   <property name="spacing" >
    <number>6</number>
   </property>
   <item>
    <widget class="QGroupBox" name="groupBox" >
     <property name="title" >
      <string>Export Options</string>
     </property>
     <layout class="QGridLayout" >
      <property name="margin" >
       <number>8</number>
      </property>
      <property name="spacing" >
       <number>6</number>
      </property>
      <item row="1" column="0" >
       <widget class="QRadioButton" name="radioButton_2" >
        <property name="text" >
         <string>&amp;DocBook</string>
        </property>
       </widget>
      </item>
      <item row="0" column="0" >
       <widget class="QRadioButton" name="radioButton" >
        <property name="text" >
         <string>&amp;LaTeX</string>
        </property>
        <property name="checked" >
         <bool>true</bool>
        </property>
       </widget>
      </item>
      <item row="1" column="1" >
       <widget class="QCheckBox" name="checkBox_2" >
        <property name="text" >
         <string>Include p&amp;ictures</string>
        </property>
        <property name="checked" >
         <bool>true</bool>
        </property>
       </widget>
      </item>
      <item row="5" column="0" >
       <spacer>
        <property name="orientation" >
         <enum>Qt::Vertical</enum>
        </property>
        <property name="sizeHint" >
         <size>
          <width>20</width>
          <height>40</height>
         </size>
        </property>
       </spacer>
      </item>
      <item row="0" column="1" >
       <widget class="QCheckBox" name="checkBox" >
        <property name="text" >
         <string>&amp;Compress</string>
        </property>
       </widget>
      </item>
      <item row="2" column="0" >
       <widget class="QRadioButton" name="radioButton_2_2" >
        <property name="text" >
         <string>&amp;HTML</string>
        </property>
       </widget>
      </item>
      <item row="3" column="0" >
       <widget class="QRadioButton" name="radioButton_3" >
        <property name="text" >
         <string>&amp;PostScript</string>
        </property>
       </widget>
      </item>
      <item row="4" column="0" >
       <widget class="QRadioButton" name="radioButton_4" >
        <property name="text" >
         <string>PD&amp;F</string>
        </property>
       </widget>
      </item>
      <item row="2" column="1" >
       <widget class="QCheckBox" name="checkBox_3" >
        <property name="text" >
         <string>Include &amp;metadata</string>
        </property>
       </widget>
      </item>
      <item row="3" column="1" >
       <widget class="QCheckBox" name="checkBox_4" >
        <property name="text" >
         <string>Create inde&amp;x</string>
        </property>
        <property name="checked" >
         <bool>true</bool>
        </property>
       </widget>
      </item>
     </layout>
    </widget>
   </item>
  </layout>
 </widget>
 <pixmapfunction></pixmapfunction>
 <resources/>
 <connections/>
</ui>








#include <QtGui>
#include <QtUiTools>

#include "mywidget.h"


QWidget *loadCustomWidget(QWidget *parent)
{
    QUiLoader loader;
    QWidget *myWidget;

    QStringList availableWidgets = loader.availableWidgets();

    if (availableWidgets.contains("AnalogClock"))
        myWidget = loader.createWidget("AnalogClock", parent);

    return myWidget;
}


int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    MyWidget widget;
    widget.show();

    QWidget *customWidget = loadCustomWidget(0);
    customWidget->show();
    return app.exec();
}

   
    
  








Related examples in the same category

1.Qt UI test