On Wednesday 25 February 2009 12:05:52 Dong Tiger wrote: > 2008/12/30 Alexis Ménard <men...@kde.org> > > > Unfortunately you can't it is a bug in Qt. > > > > You can take a look to the task tracker of Qt Number 231114 and 211500. I > > guess it is what you try to solve. The fix is in 4.4 branch (so scheduled > > for 4.4.4) and in 4.5. > > I still can't get this work even with latest Qt4.5. I've attached code of a > sample plasmoid which demonstrate the problem. You are welcomed to try it > out. Right click on the applet to modify its child widget size. > > > As a workaround you have to manage the resize of your applet by hand when > > the size of the layout change. > > The question is how can I do it? When the embedded QGraphicsWidget need to > enlarge, say from 200x200 to 400x400, how can I decide what the applet size > should be?
Does this work? Petri
#include "plasma-tutorial1.h" #include <QPainter> #include <QFontMetrics> #include <QSizeF> #include <QPainter> #include <QApplication> #include <QInputDialog> QSizePolicy::Policy policy = QSizePolicy::Preferred; class MyGraphicsWidget: public QGraphicsWidget { public: MyGraphicsWidget(QGraphicsItem * parent = 0) : QGraphicsWidget(parent) {} void paint(QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) { QRectF r = rect(); p->setPen(QColor(0, 0, 255)); p->drawLine(r.left(), r.top(), r.right(), r.bottom()); p->drawLine(r.left(), r.bottom(), r.right(), r.top()); p->drawRect(r); QSizeF s = parentWidget()->size(); p->drawText(10, 10, QString("Child:%1x%2").arg(size().width()).arg(size().height())); p->drawText(10, 30, QString("Parent:%1x%2").arg(s.width()).arg(s.height())); } }; static void embedWidget(QGraphicsWidget *parent, QWidget *widget) { } PlasmaTutorial1::PlasmaTutorial1(QObject *parent, const QVariantList &args) : Plasma::Applet(parent, args), layout_(NULL), child_(NULL) { resize(200, 200); child_ = new MyGraphicsWidget(this); layout_ = new QGraphicsLinearLayout(this); layout_->setSpacing(0); layout_->setContentsMargins(0, 0, 0, 0); layout_->addItem(child_); layout_->setSizePolicy(policy, policy); setLayout(layout_); setBackgroundHints(Plasma::Applet::NoBackground); } PlasmaTutorial1::~PlasmaTutorial1() { if (hasFailedToLaunch()) { // Do some cleanup here } else { // Save settings } } void PlasmaTutorial1::init() { } void PlasmaTutorial1::paintInterface(QPainter *p, const QStyleOptionGraphicsItem *option, const QRect &contentsRect) { } void PlasmaTutorial1::constraintsEvent(Plasma::Constraints constraints) { kDebug() << "constraintsEvent"; } void PlasmaTutorial1::contextMenuEvent(QGraphicsSceneContextMenuEvent * event) { QSize s = child_->size().toSize(); int size = QInputDialog::getInteger(NULL, "Set Size", "Set size", s.width()*1000 + s.height()); if (size == s.width()*1000 + s.height()) return; resize(QSizeF(size/1000, size%1000) + (rect().size() - contentsRect().size())); } #include "plasma-tutorial1.moc"
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ Plasma-devel mailing list Plasma-devel@kde.org https://mail.kde.org/mailman/listinfo/plasma-devel