Difference between revisions of "Development/Tutorials/KDE3/KDockWidget"

Jump to: navigation, search
(Dock Widget Tutorial)
m (Text replace - "</code>" to "</syntaxhighlight>")
 
(4 intermediate revisions by 3 users not shown)
Line 3: Line 3:
 
This tutorial shows examples on how to create docking widgets that dock to your main application.
 
This tutorial shows examples on how to create docking widgets that dock to your main application.
  
The first confusing part about making docking windows is that you need to subclass KDockMainWindow rather than KMainWindow for your KDE application. In addition to converting over to KDockMainWindow, you will need to create two dock widget in order to notice any docking windows. In the example you will notice that one dock widget becomes the station for the other docking widget.
+
The first confusing part about making docking windows is that you need to subclass {{class|KDockMainWindow|kdelibs|3.5}} rather than {{class|KMainWindow|kdelibs|3.5}} for your KDE application. In addition to converting over to KDockMainWindow, you will need to create two dock widget in order to notice any docking windows. In the example you will notice that one dock widget becomes the station for the other docking widget.
 
+
'''Note:''' If you find this explanation incorrect please let me know.
+
  
 
[[Image:Docked.gif]]
 
[[Image:Docked.gif]]
Line 19: Line 17:
 
4. Name the Application '''tutKDockWidget'''
 
4. Name the Application '''tutKDockWidget'''
  
5. Copy and paste the following files over '''tutKDockWidget.cpp''' and '''tutKDockWidget.h'''
+
5. Copy and paste the following files over '''{{path|tutKDockWidget.cpp}}''' and '''{{path|tutKDockWidget.h}}'''
 
+
[[Category:KDE3]]
+
  
 
== tutkdockwidget.cpp ==
 
== tutkdockwidget.cpp ==
  
<code cppqt>
+
<syntaxhighlight lang="cpp-qt">
 
#include "tutkdockwidget.h"
 
#include "tutkdockwidget.h"
  
Line 79: Line 75:
  
 
#include "tutkdockwidget.moc"
 
#include "tutkdockwidget.moc"
</code>
+
</syntaxhighlight>
  
 
== kdockwidget.h ==
 
== kdockwidget.h ==
  
<code cppqt>
+
<syntaxhighlight lang="cpp-qt">
 
#ifndef _TUTKDOCKWIDGET_H_
 
#ifndef _TUTKDOCKWIDGET_H_
 
#define _TUTKDOCKWIDGET_H_
 
#define _TUTKDOCKWIDGET_H_
Line 110: Line 106:
  
 
#endif // _TUTKDOCKWIDGET_H_
 
#endif // _TUTKDOCKWIDGET_H_
</code>
+
</syntaxhighlight>
 +
 
 +
 
 +
[[Category:KDE3]]

Latest revision as of 21:52, 29 June 2011

[edit] Dock Widget Tutorial

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

The first confusing part about making docking windows is that you need to subclass KDockMainWindow rather than KMainWindow for your KDE application. In addition to converting over to KDockMainWindow, you will need to create two dock widget in order to notice any docking windows. In the example you will notice that one dock widget becomes the station for the other docking widget.

Docked.gif

Start a new project using kdevelop

1. First start Kdevelop.

2. Select New Project from the project menu

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

4. Name the Application tutKDockWidget

5. Copy and paste the following files over tutKDockWidget.cpp and tutKDockWidget.h

[edit] tutkdockwidget.cpp

#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 docking station from being 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"

[edit] kdockwidget.h

#ifndef _TUTKDOCKWIDGET_H_
#define _TUTKDOCKWIDGET_H_
 
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
 
#include <kdockwidget.h>
 
//Important: notice that its KDockMainWindow rather than KMainWindow
class tutKDockWidget : public KDockMainWindow
{
    Q_OBJECT
public:
    /**
     * Default Constructor
     */
    tutKDockWidget();
 
    /**
     * Default Destructor
     */
    virtual ~tutKDockWidget();
};
 
#endif // _TUTKDOCKWIDGET_H_

This page was last modified on 29 June 2011, at 21:52. This page has been accessed 4,347 times. Content is available under Creative Commons License SA 3.0 as well as the GNU Free Documentation License 1.2.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal