This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Plasma::IconWidget shape and layout problem

Tags: None
(comma "," separated)
mobilehunter
Registered Member
Posts
17
Karma
0
OS
Hi,
I'm trying to use iconwidget as button, and i use svg for it's drawing.
But i got this result Image
The second row is from inkscape as reference.
Below my code snippet:
Code: Select all
void KerenApplet::createLayout()
{
    QGraphicsLinearLayout *mainLayout = new QGraphicsLinearLayout(Qt::Vertical);
    QGraphicsLinearLayout *controlLayout = new QGraphicsLinearLayout(Qt::Horizontal);

    QGraphicsWidget *spacerLeft = new QGraphicsWidget();
    spacerLeft->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
    spacerLeft->setMaximumHeight(IconSize(KIconLoader::Panel));

    QGraphicsWidget *spacerRight = new QGraphicsWidget();
    spacerRight->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
    spacerRight->setMaximumHeight(IconSize(KIconLoader::Panel));

    controlLayout->addItem(spacerLeft);
    controlLayout->addItem(mPictureButton);//Plasma::IconWidget
    controlLayout->addItem(mVideoButton);//Plasma::IconWidget
    controlLayout->addItem(spacerRight);
   
    mControlFrame->setLayout(controlLayout);//Plasma::Frame

    mainLayout->setContentsMargins(0, 0, 0, 0);
    mainLayout->addItem(mPreviewWidget);       
    mainLayout->addItem(mControlFrame);

    if (!mWidget) {
        mWidget = new QGraphicsWidget(this);
        mWidget->setLayout(mainLayout);
        mWidget->setMinimumSize(500,400);
    }
}


1. Does my centering layout codes correct?
2. Why the button shape does not look perfect like reference image?


Thanks

edited to include whole function

Last edited by mobilehunter on Mon Oct 12, 2009 9:47 am, edited 1 time in total.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
The centering code looks fine from a normal Qt layouting perspective, however I do not know if setting the maximum size is needed.

I do not know why the button shape is disfigured, however it could certainly be the custom layouting. Have you tried disabling it?


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
mobilehunter
Registered Member
Posts
17
Karma
0
OS
bcooksley wrote:The centering code looks fine from a normal Qt layouting perspective, however I do not know if setting the maximum size is needed.

I do not know why the button shape is disfigured, however it could certainly be the custom layouting. Have you tried disabling it?

I edited my first post above.

I need to set maximum size otherwise, the mControlFrame will occupy half of the applet size.
Sorry i don't understand with 'custom layouting'. Is it visible from my codes above?
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
The problem is likely in the instantiation of the Plasma::IconWidgets. Can you please post the complete code of your widget?


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
mobilehunter
Registered Member
Posts
17
Karma
0
OS
More codes, iconwidget is created at applet constructor.
Code: Select all
KerenApplet::KerenApplet(QObject *parent, const QVariantList &args)
        : Plasma::PopupApplet(parent, args),
        mCaptureType(KerenApplet::Picture),
        mWidget(0),mVideoGst(0)
{
    QApplication::setAttribute(Qt::AA_NativeWindows);
   
    QtGstreamer::qGstInit(NULL,NULL);
    setHasConfigurationInterface(true);
    setAspectRatioMode(Plasma::IgnoreAspectRatio);
    resize(420, 340);
    setPopupIcon("camera-web");

    mPreviewWidget = new PreviewWidget(this);

    connect(mPreviewWidget, SIGNAL(countDownFinished()), this, SLOT(slotCountDownFinished()));

    mControlFrame = new Plasma::Frame(this);
    mControlFrame->setFrameShadow(Plasma::Frame::Raised);
   
    mPictureButton = new Plasma::IconWidget();
    mPictureButton->setSvg("widgets/keren","camcorder");
    mVideoButton = new Plasma::IconWidget();
    mVideoButton->setSvg("widgets/keren","camcorder_on");
   
    connect(mPictureButton, SIGNAL(clicked()), this, SLOT(slotTakePicture()));
    connect(mVideoButton, SIGNAL(clicked()), this, SLOT(slotTakeVideo()));

    mAlbumName="default";
    mIsRecordingVideo=false;
    mVideoFrameSize = QSize(320,240);
}

void KerenApplet::init()
{
    createLayout();
}


void KerenApplet::createLayout()
{
    QGraphicsLinearLayout *mainLayout = new QGraphicsLinearLayout(Qt::Vertical);
    QGraphicsLinearLayout *controlLayout = new QGraphicsLinearLayout(Qt::Horizontal);

    QGraphicsWidget *spacerLeft = new QGraphicsWidget();
    spacerLeft->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
    spacerLeft->setMaximumHeight(IconSize(KIconLoader::Panel));

    QGraphicsWidget *spacerRight = new QGraphicsWidget();
    spacerRight->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
    spacerRight->setMaximumHeight(IconSize(KIconLoader::Panel));

    controlLayout->addItem(spacerLeft);
    controlLayout->addItem(mPictureButton);
    controlLayout->addItem(mVideoButton);
   
    controlLayout->addItem(spacerRight);
    mControlFrame->setLayout(controlLayout);

    mainLayout->setContentsMargins(0, 0, 0, 0);
    mainLayout->addItem(mPreviewWidget);       
    mainLayout->addItem(mControlFrame);

    if (!mWidget) {
        mWidget = new QGraphicsWidget(this);
        mWidget->setLayout(mainLayout);
        mWidget->setMinimumSize(500,400);
    }
}

User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
It is possible the IconWidget is forced to creating a square representation of itself, as icons are virtually always square. Does it render them correctly with Plasma::Svg?


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
mobilehunter
Registered Member
Posts
17
Karma
0
OS
Using Plasma::SvgWidget
Image
I also put setMinimumSize or the button will appear like previous IconWidget's screenshot.
mobilehunter
Registered Member
Posts
17
Karma
0
OS
I ended up creating new class for button.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Thanks for the update on the workaround.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]


Bookmarks



Who is online

Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]