kde-plasmaqt4.7kde4

Setting size for Plasma::PushButton?


I'm trying to implement a simple KDE plasma plugin , which contains two PushButtons and a KLineEdit ,

But it seems KLineEdit and the PushButton has a minimum size , if the panel doesn't have enough height , some parts will disappear on the panel , it doens't shrink as the panel shrinks.

Since i already set the QSizePolicy to minimum , i don't understand why it's now resizing as user drag the panel ?

Thanks , and here's the primary class file:

#include <Plasma/Theme>
#include <Plasma/Corona>
#include <Plasma/Containment>
#include <Plasma/ToolTipManager>

K_EXPORT_PLASMA_APPLET(runcommand, RunCommandApplet)

RunCommandApplet:: RunCommandApplet(QObject *parent, const QVariantList &args) : Plasma::Applet(parent, args)
{
        paste_button = new Plasma::PushButton (this);
        paste_button->setText (tr("Pa"));

        m_button = new Plasma::PushButton (this);
        m_button->setText (tr("Ki"));

        m_lineEdit = new Plasma::LineEdit (this);

        QGraphicsLinearLayout *layout = new QGraphicsLinearLayout ();
        layout->addItem (m_button);
        layout->addItem (paste_button);
        layout->addItem (m_lineEdit);
            setLayout(layout);

        constraintsEvent(Plasma::FormFactorConstraint | Plasma::ImmutableConstraint);

        Plasma::ToolTipManager::self()->setContent(this, Plasma::ToolTipContent(i18n("Client"), i18n("Some Client"), KIcon("system-run").pixmap(IconSize(KIconLoader::Desktop))));

}

void RunCommandApplet::constraintsEvent(Plasma::Constraints constraints)
{
        m_button->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
        paste_button->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
        m_lineEdit->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
}

Solution

  • Plasm::PushButtons QSizePolicy is Minimum by default. Try setting QSizePolicy::ShrinkFlag flag.