Development/Tutorials/KDE3/KDockWidget: Difference between revisions

From KDE TechBase
(category KDE3)
Line 14: Line 14:


[[Category:KDE3]]
[[Category:KDE3]]
<code cppqt>
#include "tutkdockwidget.h"
#include <qlabel.h>
#include <kdockwidget.h>
#include <klocale.h>
tutKDockWidget::tutKDockWidget()
    : KDockMainWindow( 0, "tutKDockWidget" )
{
// set the shell's ui resource file
setXMLFile("tutkdockwidgetui.rc");
//define the main dock - Note: this window does not dock/undock
KDockWidget* mainDock;
mainDock = createDockWidget( "Falk's MainDockWidget", 0, 0L, "main_dock_widget");
//This can be any widget control
QLabel* cw = new QLabel("label1",mainDock,"label1");
mainDock->setWidget( cw);
//This informs how docking will take place
//KDockWidget::DockCorner = dock to all sides
//KDockWidget::DockFullSite = dock to all sides + center
//KDockWidget::DockFullDocking = KDockWidget::DockFullSite
mainDock->setDockSite(KDockWidget::DockFullSite);
//Prevent main docking for beable able to dock
mainDock->setEnableDocking(KDockWidget::DockNone);
setView( mainDock);
//this tells the kDockMainWindow what control to use as its master dock control
setMainDockWidget( mainDock);
//Here is really where the window that docks/undocked is defined
KDockWidget* dockLeft;
dockLeft = createDockWidget( "Intially left one", 0, 0L, i18n("The left dockwidget"));
//Again this can be any control
QLabel* aw = new QLabel("label2",dockLeft,"label2");
dockLeft->setWidget( aw);
//Dock the control to the left side with 20 width
dockLeft->manualDock( mainDock,KDockWidget::DockLeft,20);
}
tutKDockWidget::~tutKDockWidget()
{
}
#include "tutkdockwidget.moc"
</code>

Revision as of 03:02, 6 June 2007

Dock Widget Tutorial

This tutorial shows examples on how to create docking widgets that dock to your main application.

Start a new project using kdevelop

1. First start the Kdevelop.

2. Select New Project from the project menu

3. Select Simple KDE application located under C++ -> KDE

  1. include "tutkdockwidget.h"
  1. include <qlabel.h>
  1. include <kdockwidget.h>
  2. include <klocale.h>

tutKDockWidget::tutKDockWidget()

   : KDockMainWindow( 0, "tutKDockWidget" )

{ // set the shell's ui resource file setXMLFile("tutkdockwidgetui.rc");

//define the main dock - Note: this window does not dock/undock KDockWidget* mainDock; mainDock = createDockWidget( "Falk's MainDockWidget", 0, 0L, "main_dock_widget");

//This can be any widget control QLabel* cw = new QLabel("label1",mainDock,"label1"); mainDock->setWidget( cw);

//This informs how docking will take place //KDockWidget::DockCorner = dock to all sides //KDockWidget::DockFullSite = dock to all sides + center //KDockWidget::DockFullDocking = KDockWidget::DockFullSite mainDock->setDockSite(KDockWidget::DockFullSite);

//Prevent main docking for beable able to dock mainDock->setEnableDocking(KDockWidget::DockNone);


setView( mainDock);

//this tells the kDockMainWindow what control to use as its master dock control setMainDockWidget( mainDock);

//Here is really where the window that docks/undocked is defined KDockWidget* dockLeft; dockLeft = createDockWidget( "Intially left one", 0, 0L, i18n("The left dockwidget"));

//Again this can be any control QLabel* aw = new QLabel("label2",dockLeft,"label2"); dockLeft->setWidget( aw);

//Dock the control to the left side with 20 width dockLeft->manualDock( mainDock,KDockWidget::DockLeft,20); }

tutKDockWidget::~tutKDockWidget() { }

  1. include "tutkdockwidget.moc"