Develop the First APP Example
About 393 wordsAbout 1 min
2025-07-17
Sample App Development
Implement a simple app that shows an interactive button.
Project Setup
- Pull the app template project Example
- Use the extension to create an app at a specified location (future enhancement)
Create the Main Window
The template project creates mainWindowService as the app’s main window by default. You can use it directly or create a custom window inheriting from TpMainWindow and use it in main.
Create a Button
Include TpButton header
#include "TpButton.h"Declare test button
TpButton *testButton_;Initialize button
testButton_ = new TpButton("Test Button", this);
testButton_->setSize(300, 70);
testButton_->move(150, 150);Full Source Code
#ifndef __MAIN_WINDOW_SERVICE_H
#define __MAIN_WINDOW_SERVICE_H
#include "TpMainWindow.h"
#include "examplesAppGlobal.h"
#include "TpButton.h"
class mainWindowService
: public TpMainWindow
{
public:
mainWindowService();
virtual ~mainWindowService();
public:
virtual bool appChange(int32_t id, int32_t pid, int32_t rotate, int32_t visible, int32_t active, int32_t color, uint8_t alpha, int32_t require) override;
protected:
virtual bool onResizeEvent(TpObjectResizeEvent *event) override;
virtual bool onRotateEvent(tpObjectRotateEvent *event) override;
virtual bool onActiveEvent(tpObjectActiveEvent *event) override;
private:
TpButton *testButton_;
};
#endif#include "mainWindowService.h"
mainWindowService::mainWindowService()
: TpMainWindow()
{
setStyleSheet(applicationDirPath() + "/../data/style.css");
setBackGroundColor(_RGB(128, 128, 128));
testButton_ = new TpButton("Test Button 1", this);
testButton_->setSize(300, 70);
testButton_->move(150, 150);
}
mainWindowService::~mainWindowService()
{
}
bool mainWindowService::appChange(int32_t id, int32_t pid, int32_t rotate, int32_t visible, int32_t active, int32_t color, uint8_t alpha, int32_t require)
{
std::cout << "mainWindowService::appChange" << std::endl;
return true;
}
bool mainWindowService::onResizeEvent(TpObjectResizeEvent *event)
{
std::cout << "mainWindowService::onResizeEvent" << std::endl;
return true;
}
bool mainWindowService::onRotateEvent(tpObjectRotateEvent *event)
{
std::cout << "mainWindowService::onRotateEvent" << std::endl;
return true;
}
bool mainWindowService::onActiveEvent(tpObjectActiveEvent *event)
{
std::cout << "mainWindowService::onActiveEvent" << std::endl;
return true;
}Build and Run
Build Code
cmake
make
make installStart the emulator
TpWMRun the app
./examplesAppResult

Copyright
Copyright Ownership:TinyPiXOS
License under:Attribution-ShareAlike 4.0 International (CC-BY-SA-4.0)
