KParts::Part Class

class KParts::Part

Base class for parts. More...

Header: #include <KParts/Part>
CMake: find_package(KF6 REQUIRED COMPONENTS Parts)
target_link_libraries(mytarget PRIVATE KF6::Parts)
Inherits: QObject and KParts::PartBase
Inherited By:

KParts::ReadOnlyPart

Public Functions

Part(QObject *parent = nullptr, const KPluginMetaData &data = {})
virtual KParts::Part *hitTest(QWidget *widget, const QPoint &globalPos)
KParts::PartManager *manager() const
(since 5.77) KPluginMetaData metaData() const
void setAutoDeletePart(bool autoDeletePart)
void setAutoDeleteWidget(bool autoDeleteWidget)
virtual QWidget *widget()

Signals

void setStatusBarText(const QString &text)
void setWindowCaption(const QString &caption)

Protected Functions

virtual void guiActivateEvent(KParts::GUIActivateEvent *event)
QWidget *hostContainer(const QString &containerName)
virtual void partActivateEvent(KParts::PartActivateEvent *event)
virtual void setWidget(QWidget *widget)

Detailed Description

A "part" is a GUI component, featuring:

  • A widget embeddedable in any application.
  • GUI elements that will be merged in the "host" user interface (menubars, toolbars... ).

About the widget:

Note that KParts::Part does not inherit QWidget. This is due to the fact that the "visual representation" will probably not be a mere QWidget, but an elaborate one. That's why when implementing your KParts::Part (or derived) you should call KParts::Part::setWidget() in your constructor.

About the GUI elements:

Those elements trigger actions, defined by the part ( action()). The layout of the actions in the GUI is defined by an XML file ( setXMLFile()).

See also ReadOnlyPart and ReadWritePart, which define the framework for a "viewer" part and for an "editor"-like part. Use Part directly only if your part doesn't fit into those.

Member Function Documentation

[explicit] Part::Part(QObject *parent = nullptr, const KPluginMetaData &data = {})

Constructor.

parent Parent object of the part.

data KPluginMetaData associated with this part, see Part::metaData()

[virtual protected] void Part::guiActivateEvent(KParts::GUIActivateEvent *event)

Convenience method which is called when the Part received a GUIActivateEvent . Reimplement this if you don't want to reimplement event and test for the event yourself or even install an event filter.

[virtual] KParts::Part *Part::hitTest(QWidget *widget, const QPoint &globalPos)

Returns the part (this, or a child part) at the given global position. This is called by the part manager to ask whether a part should be activated when clicking somewhere. In most cases the default implementation is enough. Reimplement this if your part has child parts in some areas (like in khtml or koffice)

widget the part widget being clicked - usually the same as widget(), except in koffice.

globalPos the mouse coordinates in global coordinates

[protected] QWidget *Part::hostContainer(const QString &containerName)

Convenience method for KXMLGUIFactory::container.

Returns a container widget owned by the Part's GUI.

KParts::PartManager *Part::manager() const

Returns the part manager handling this part, if any (0L otherwise).

[since 5.77] KPluginMetaData Part::metaData() const

This function was introduced in 5.77.

[virtual protected] void Part::partActivateEvent(KParts::PartActivateEvent *event)

Convenience method which is called when the Part received a PartActivateEvent . Reimplement this if you don't want to reimplement event and test for the event yourself or even install an event filter.

void Part::setAutoDeletePart(bool autoDeletePart)

By default, the part deletes itself when its widget is deleted. The hosting application can call setAutoDeletePart(false) to disable this behavior, to be able to delete the widget and then the part, independently. This is a method for the hosting application only, Part subclasses should never call this.

void Part::setAutoDeleteWidget(bool autoDeleteWidget)

By default, the widget is deleted by the part when the part is deleted. The hosting application can call setAutoDeleteWidget(false) to disable this behavior, given that the widget is usually deleted by its parent widget anyway. This is a method for the hosting application only, Part subclasses should never call this.

[signal] void Part::setStatusBarText(const QString &text)

Emitted by the part, to set a text in the statusbar of the window(s) hosting this part

[virtual protected] void Part::setWidget(QWidget *widget)

Set the main widget.

Call this in the Part-inherited class constructor.

See also widget().

[signal] void Part::setWindowCaption(const QString &caption)

Emitted by the part, to set the caption of the window(s) hosting this part

Note: this signal has only an effect on the window title if window title handling is enabled, see KParts::MainWindow::setWindowTitleHandling

[virtual] QWidget *Part::widget()

Returns the widget defined by this part, set by setWidget().

See also setWidget().