设置Plasma :: PushButton的大小?

时间:2012-01-09 10:41:10

标签: kde qt4.7 kde4

我正在尝试实现一个简单的KDE等离子插件,它包含两个PushButtons和一个KLineEdit,

但似乎KLineEdit和PushButton的最小尺寸,如果面板没有足够的高度,面板上的某些部分会消失,面板缩小时不会收缩。

由于我已经将QSizePolicy设置为最小,我不明白为什么现在当用户拖动面板时它正在调整大小?

谢谢,这是主要的类文件:

#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));
}

1 个答案:

答案 0 :(得分:1)

Plasm :: PushButtons QSizePolicy默认为最小值。尝试设置QSizePolicy :: ShrinkFlag标志。