How to make a simple PopupApplet

Giulio Camuffo giuliocamuffo at gmail.com
Sat Jan 16 23:34:58 CET 2010


On Saturday 16 January 2010 21:12:41 Shantanu Tushar Jha wrote:
> On Sat, Jan 16, 2010 at 5:08 PM, Giulio Camuffo 
<giuliocamuffo at gmail.com>wrote:
> > On Saturday 16 January 2010 05:36:41 Shantanu Tushar Jha wrote:
> > > Hello all,
> > > 
> > >     I wanted to make a simple PopupApplet which stays as an icon in the
> > > 
> > > panel and when clicked shows a popup allowing to enter username and
> > > password. The techbase extenders tutorial seems a bit overkill for this
> > > because it provides more functionality than what required in my case.
> > > So, looking at the PopupApplet API, I wrote the following code -
> > > 
> > > #include "sifyclient.h"
> > > K_EXPORT_PLASMA_APPLET(sifyclient, SifyClient)
> > > 
> > > SifyClient::SifyClient(QObject *parent, const QVariantList &args)
> > > 
> > >     : Plasma::PopupApplet(parent, args)
> > > 
> > > {
> > > 
> > >     topLevelWidget = new QGraphicsWidget;
> > >     usernameLabel = new Plasma::Label(topLevelWidget);
> > >     usernameEdit = new Plasma::LineEdit(topLevelWidget);
> > >     
> > >     usernameLabel->setText("Username");
> > >     
> > >     QGraphicsLinearLayout *usernameLayout = new
> > > 
> > > QGraphicsLinearLayout(Qt::Horizontal, topLevelWidget);
> > > 
> > >     dataTransferLayout->addItem(usernameLabel);
> > >     dataTransferLayout->addItem(usernameEdit);
> > >     
> > >     topLevelWidget->setLayout(dataTransferLayout);
> > > 
> > > }
> > > 
> > > SifyClient::~SifyClient()
> > > {
> > > 
> > >     delete topLevelWidget;
> > > 
> > > }
> > > 
> > > void SifyClient::init()
> > > {
> > > 
> > >     setPopupIcon("device-notifier");    //just for testing, will
> > >     replace
> > 
> > by
> > 
> > > appropriate one later
> > > }
> > > 
> > > QGraphicsWidget *SifyClient::graphicsWidget()
> > > {
> > > 
> > >     return topLevelWidget;
> > > 
> > > }
> > > 
> > > #include "sifyclient.moc"
> > > 
> > > 
> > > From the API, I expected this to display 'device-notifier' icon when
> > 
> > placed
> > 
> > > in panel and show the username label and line edit when clicked.
> > > Instead
> > 
> > it
> > 
> > > displays the label and line edit directly inside the panel. What am I
> > 
> > doing
> > 
> > > wrong? How to get the effect I'm trying to achieve?
> > > 
> > > Thanks
> > 
> > Try setting a a minimum size for the topLevelWidget. It should work that
> > way.
> 
> Thanks, that worked! I used 'topLevelWidget->setMinimumSize(250, 250);' in
> the constructor and now it shows the icon in the panel.
> But now, If I click the icon, nothing pops up. Only If I move the applet
> from the panel to the desktop (when it shows the topLevelWidget with a
> label and lineEdit inside it) and then move it back into the panel, the
> popup shows on clicking the icon. Every time I do this, the following is
> output to the terminal -
> 
> plasma-desktop(5365)/plasma ItemSpace::resizeItem: Resizing QRectF(787,637
> 32x32) to QRectF(787,637 278x278)
> 
> Any idea what I'm missing?
> 
> Thanks
> 
> > _______________________________________________
> > Plasma-devel mailing list
> > Plasma-devel at kde.org
> > https://mail.kde.org/mailman/listinfo/plasma-devel

I had a similar problem, some time ago, and if I remeber correctly the problem 
was that the parent of graphicWidget() was 0. Try to change "topLevelWidget = 
new QGraphicsWidget;" with "topLevelWidget = new QGraphicsWidget(this);".

On a side note it is better to instantiate those pointers in this way:

SifyClient::SifyClient(QObject *parent, const QVariantList &args)
    : Plasma::PopupApplet(parent, args),
      topLevelWidget(new QGraphicsWidget(this)),
      ...
{


More information about the Plasma-devel mailing list