0

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

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

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

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

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

1 回答 1

1

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

于 2012-01-11T11:15:22.060 回答