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? > > 2008/12/30 Dong Tiger <idlecat...@gmail.com> > >> Hi, >> >> A QGraphicsWidget is embeded into Plasma::Applet through >> QGraphicsLinearLayout. When this QGraphicsWidget's size changes, how to get >> the applet's size adjusted accordingly? >> >> The code snippet looks like: >> >> child = new MyGraphicsWidget(applet); >> layout = new QGraphicsLinearLayout(applet); >> layout->setSpacing(0); >> layout->addItem(child); >> applet->setLayout(layout); >> >> >> Regards, >> -- >> Tiger >> >> _______________________________________________ >> Plasma-devel mailing list >> Plasma-devel@kde.org >> https://mail.kde.org/mailman/listinfo/plasma-devel >> >> > > _______________________________________________ > Plasma-devel mailing list > Plasma-devel@kde.org > https://mail.kde.org/mailman/listinfo/plasma-devel > >
# Project Needs a name ofcourse project(plasma-tutorial1) # Find the required Libaries find_package(Qt4 REQUIRED) find_package(KDE4 REQUIRED) include(KDE4Defaults) add_definitions (${QT_DEFINITIONS} ${KDE4_DEFINITIONS}) include_directories( ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${KDE4_INCLUDES} ${Qt4_INCLUDES}} ) # We add our source code here set(tutorial1_SRCS plasma-tutorial1.cpp) # Now make sure all files get to the right place kde4_add_plugin(plasma_applet_tutorial1 ${tutorial1_SRCS}) target_link_libraries(plasma_applet_tutorial1 ${KDE4_PLASMA_LIBS} ${KDE4_KDEUI_LIBS} ${Qt4_LIBS}) install(TARGETS plasma_applet_tutorial1 DESTINATION ${PLUGIN_INSTALL_DIR}) install(FILES plasma-applet-tutorial1.desktop DESTINATION ${SERVICES_INSTALL_DIR})
#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_->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; child_->resize(size/1000, size%1000); child_->setPreferredSize(size/1000, size%1000); // child_->setMinimumSize(size/1000, size%1000); setPreferredSize(layout_->preferredSize()); updateGeometry(); kDebug() << "mouseDoubleClickEvent"; } #include "plasma-tutorial1.moc"
#ifndef Tutorial1_HEADER #define Tutorial1_HEADER // We need the Plasma Applet headers #include <KIcon> #include <Plasma/Applet> #include <Plasma/Svg> #include <QGraphicsLinearLayout> class QSizeF; // Define our plasma Applet class PlasmaTutorial1 : public Plasma::Applet { Q_OBJECT public: // Basic Create/Destroy PlasmaTutorial1(QObject *parent, const QVariantList &args); ~PlasmaTutorial1(); // The paintInterface procedure paints the applet to screen void paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, const QRect& contentsRect); void init(); protected: virtual void constraintsEvent(Plasma::Constraints constraints); virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent * event); QGraphicsLinearLayout *layout_; QGraphicsWidget* child_; }; // This is the command that links your applet to the .desktop file K_EXPORT_PLASMA_APPLET(tutorial1, PlasmaTutorial1) #endif
plasma-applet-tutorial1.desktop
Description: Binary data
_______________________________________________ Plasma-devel mailing list Plasma-devel@kde.org https://mail.kde.org/mailman/listinfo/plasma-devel