Images (for developers)

From Trinity Desktop Project Wiki
Revision as of 20:55, 25 November 2023 by Blu256 (talk | contribs) (Switch to the new TDE class template)
Jump to navigation Jump to search
Messagebox warning.png
Work in progress
This page has been marked as undergoing heavy editing by user Blu256. Please be patient.

Working with images is an important part of a graphical application, whether it's a simple application or a complex graphical suite. In TQt/TDE, this can be as simple as learning to use a few classes. This guide aims to be a good guide for developers who want to work with TQt/TDE.

Image classes

  • TQPixmap API is one of the two basic image classes provided by TQt.
It is, essentially, a paint device, so it is optimized for drawing. You'll see this class used a lot (more than TQImage) because of this quality.
  • TQImage API is the other basic image class.
According to the API docs, it is "a hardware-independent pixmap representation" and it is optimized for I/O operations and direct pixel access and manipulation.
  • TQIconSet API is a helper class for icons.
Compared to the basic image classes, this class does not represent a single image, but a set of images which correspond to an icon. A folder icon can come in different sizes (a different image file corresponds to each size), but it is still considered to be the same icon.

Usually you won't need more advanced classes.

Loading an image

The simplest way to load an image is to use the constructor of the TQPixmap API class with the path of the file you want to load. If the file is located in one of your application paths (e.g. the share folder) use the TDEStandardDirs API class.

If you want to load an icon, the simplest (and by far the most preferred) way to do so is via the TDEIconLoader API class. For TDE applications you don't even have to explicitly initialize this object. You can access an instance of this class through the `kapp` pointer of the TDEApplication API class. The icon loader class makes sure that recommended settings are used for the kind of icon you are loading, so you usually need to provide a `group` parameter of type TDEIcon::Group which defines the type of icon that you are loading and will decide its size and whether any effects will be applied to it. For example, to load a folder icon with the default settings for a toolbar icon:

TQPixmap icon = kapp->iconLoader()->loadIcon("folder", TDEIcon::Toolbar);

Displaying an image

Images can be used in quite a few widgets, including labels, text views and buttons. These widgets offer constructors and/or functions where you can pass an image as an argument (usually as a TQPixmap API or a TQIconSet API.

The following example creates a push button with a folder icon from the icon theme:

TQIconSet icon = kapp->iconLoader()->loadIconSet("folder", TDEIcon::Toolbar);
TQPushButton *button = new TQPushButton(icon, i18n("Open folder..."), this);

If you want to display an image as standalone, you first need a widget where you will display it. Usually, a TQLabel API should be enough.