XuvTools is developed in a cooperative effort from:
  • Chair of Pattern Recognition and Image Processing [www]
  • Friedrich Miescher Institute for Biomedical Research [www]
  • Center for Biological Systems Analysis [www]

This is an old revision of the document!

Qt Designer

When designing a user interface element with Qt designer, several ways to include this new element into the GUI are possible. In order to have a defined coding style for XuvTools, please stick to the following instructions when using the designer.

Copy-Paste Sample Code: QuickStart with GuiElement example

We use an example gui element, class name “GuiElement”. As you can see below, there are no explicit signal connections necessary in GuiElementQt. Instead, naming functions in the pattern

void on_<element-name>_<signal-name>();

enables automatic signal connection within Qt. As an example, the function on_mDoSomethingPushButton_released() is invoked when the QPushButton mDoSomethingPushButton, member of GuiElementQt.ui, is released.

(1) Design the UI element in Qt designer

Qt Designer Widgets


<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <widget class="QWidget" name="GuiElementQtClass">
  <property name="geometry">
  <property name="windowTitle">
  <layout class="QGridLayout">
   <item row="1" column="0">
    <widget class="QPushButton" name="mDoSomethingPushButton">
     <property name="text">
      <string>Push Me</string>
 <layoutdefault spacing="6" margin="11"/>

(2) Create a corresponding C++ class header, inherits from UI class

The header of your new class file should have the following layout:


// base class: QWidget
#include <QWidget>
// our Qt designer widget
#include "ui_GuiElementQt.h"
using namespace Ui;
class GuiElementQt : public QWidget, public GuiElementQtClass
  GuiElementQt(QWidget *parent = 0);
  virtual ~GuiElementQt();
private slots:
  void on_mDoSomethingPushButton_pushed();
  void on_mDoSomethingPushButton_released();

(3) Create a corresponding C++ class implementation (as few Qt as possible)

The source of your new class file should have the following layout:


#include "GuiElementQt.hh"
GuiElementQt::GuiElementQt(QWidget *aParent)
 : QWidget(aParent)
  // This will call the Qt designer widget constructor
  // here we could add our own GUI initialization:
void GuiElementQt::on_mDoSomethingPushButton_pushed()
  std::cerr << __FILE__ << ":" << __LINE__ << " button was pushed." << std::endl;
void GuiElementQt::on_mDoSomethingPushButton_released()
  std::cerr << __FILE__ << ":" << __LINE__ << " button was released." << std::endl;
devel/qt_designer.1260312601.txt.gz · Last modified: 2009/12/08 23:50 by mario
Contact: admin(a)xuvtools.org