[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-panel-devel
Subject:    can't get qgraphicsgridlayout to resize properly
From:       Amritpal Bath <amrit () transamrit ! net>
Date:       2009-08-25 1:58:11
Message-ID: 200908241858.11239.amrit () transamrit ! net
[Download RAW message or body]

I've got a Plasma::Applet containing a QGraphicsGridLayout, which has a couple 
of QGraphicsWidgets (QLabels via QGraphicsProxyWidget).

The text in my layout gets updated periodically after running an external 
process, but I can't quite get the resizing to work properly.  I've attached a 
similar example, with a layout containing two QPushButtons.

I try to adjust the height of the buttons, layout, AND the Applet, but nothing 
I've tried will make the buttons taller.  It sounds like maybe I'm missing 
something about QSizePolicy, but I'm not sure.

Can someone please explain the relationship between Plasma::Applet and 
QLayout, and why the attached code does not make the buttons taller?  As you 
can see from the .cpp, I've tried most/all things I could find.

Thanks!



-- 
Amrit
ICQ: 3173735
AIM: ThatComputerGuy
http://transamrit.net/

["resizeplasmoid.cpp" (text/x-c++src)]

#include <QGraphicsGridLayout>
#include <QGraphicsProxyWidget>
#include <QPushButton>
#include <QTimer>

#include <plasma/svg.h>
#include <plasma/theme.h>

#include "resizeplasmoid.h"

K_EXPORT_PLASMA_APPLET(resizeplasmoid, ResizePlasmoid)

ResizePlasmoid::ResizePlasmoid(QObject* parent, const QVariantList& args)
    : Plasma::Applet(parent, args), _layout(NULL)
{
  resize(300, 100);
}

ResizePlasmoid::~ResizePlasmoid()
{
}

void ResizePlasmoid::init()
{
  _layout = new QGraphicsGridLayout();
  setLayout(_layout);
  // 1
  _button1 = new QPushButton("foo");
  _proxy1 = new QGraphicsProxyWidget;
  _proxy1->setWidget(_button1);
  _layout->addItem(_proxy1, 0, 0);
  _layout->setRowStretchFactor(0, 50);

  // 2
  _button2 = new QPushButton("bar");
  _proxy2 = new QGraphicsProxyWidget;
  _proxy2->setWidget(_button2);
  _layout->addItem(_proxy2, 1, 0);
  _layout->setRowStretchFactor(1, 50);

  resize(300, 200);

  QTimer* timer = new QTimer(this);
  connect(timer, SIGNAL(timeout()), this, SLOT(doResize()));
  timer->start(3000); // 3 sec.
}

void ResizePlasmoid::doResize()
{
  static unsigned h = 300;
  static unsigned w = 300;
  h += 20;
  //w += 20;

  // stop eventually.
  if (h > 500) {
    printf("giving up.\n");
    fflush(stdout);
    return;
  }

  printf("ABOUT TO GROW to %u x %u.\n", w, h);
  fflush(stdout);
  _layout->setPreferredSize(w, h);
  resize(w, h);

  unsigned bW = _button1->width();
  unsigned bH = _button1->height() + 10;
  printf("resizing buttons to %u x %u.\n", bW, bH);
  _button1->resize(bW, bH);
  _button2->resize(bW, bH);
  _proxy1->resize(bW, bH);
  _proxy2->resize(bW, bH);

  update();
}

#include "resizeplasmoid.moc"

["resizeplasmoid.h" (text/x-chdr)]

#ifndef RESIZEPLASMOID_H
#define RESIZEPLASMOID_H

#include <Plasma/Applet>

class ResizePlasmoid : public Plasma::Applet
{
  Q_OBJECT
  public:
    ResizePlasmoid(QObject* parent, const QVariantList& args);
    ~ResizePlasmoid();

    void init();

  public slots:
    void doResize();

  private:
    QGraphicsGridLayout*        _layout;
    QPushButton*                _button1;
    QPushButton*                _button2;
    QGraphicsProxyWidget*       _proxy1;
    QGraphicsProxyWidget*       _proxy2;
};

#endif // RESIZEPLASMOID_H

["resizeplasmoid.desktop" (application/x-desktop)]
["CMakeLists.txt" (text/x-cmake)]

project(resizeplasmoid)

find_package(KDE4 REQUIRED)
include(${QT_USE_FILE})
include(KDE4Defaults)

add_definitions(${QT_DEFINITIONS} ${KDE4_DEFINITIONS})
include_directories(
  ${CMAKE_SOURCE_DIR}
  ${CMAKE_BINARY_DIR}
  ${KDE4_INCLUDES}
  )

set(resizeplasmoid_SRCS resizeplasmoid.cpp)

kde4_add_plugin(resizeplasmoid ${resizeplasmoid_SRCS})
target_link_libraries(resizeplasmoid ${KDE4_PLASMA_LIBS} ${KDE4_KDEUI_LIBS} ${QT_LIBRARIES})

install(TARGETS resizeplasmoid
        DESTINATION ${PLUGIN_INSTALL_DIR})

install(FILES resizeplasmoid.desktop
        DESTINATION ${SERVICES_INSTALL_DIR})


_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic