PDA

View Full Version : About Flick Charm



sayuri
20th May 2010, 11:13
Hello Everyone,

I am new here and started QT just two months ago.

The application that I have to develop need move 10 items up and down so I use flickcharm. It works well :o but my issue is that when that widget first loads. it first show the items in middle. I need to show the item on the top when that widget first loads. So where do I have to motify? I did add some code in main() but I didn't do anything. :confused: so anyone tell me how to do that?

Thanks in advance :o

For more information about how I used the flickcharm:
When I used the flickcharm, I did write the code exactly like the colored example one in the flickcharm. But I didn't need to use QWebView library so I earsed the QWebView portion in flickcharm.cpp

tbscope
20th May 2010, 11:35
You need to give a lot more information for such a specific question.
Post your code please.

sayuri
21st May 2010, 03:42
sorry....here my code




/////////////////////////////InfoBox.cpp///////////////////////////

#include "infobox.h"

InfoBox::InfoBox(QWidget *parent)
{
int w = 640;// - height
int h = 480;// - width

this->setFixedSize(h,150);
this->setStyleSheet("background-color: black; color: white; border: 1px solid white;");

lblImage_.setFixedSize(80,100);
lblTitle_.setSizePolicy(QSizePolicy(QSizePolicy::M inimumExpanding, QSizePolicy::Preferred));
lblDuration_.setSizePolicy(QSizePolicy(QSizePolicy ::MinimumExpanding, QSizePolicy::Preferred));

lblImage_.setAlignment(Qt::AlignTop);

lblTitle_.setText("Title Name");
lblImage_.setText("");
lblDuration_.setText("100 mins");

lblImage_.setStyleSheet("background-color: Blue; color: white; border-radius: 4px; border: 0px solid none;");
lblTitle_.setStyleSheet("background-color: black; color: white; border: 0px solid none;");
lblDuration_.setStyleSheet("background-color: black; color: white; border: 0px solid none;");

QVBoxLayout *lytInfo_ = new QVBoxLayout;
lytInfo_->addWidget(&lblTitle_);
lytInfo_->addWidget(&lblDuration_);

QHBoxLayout *lytMain_ = new QHBoxLayout;
lytMain_->addWidget(&lblImage_);
lytMain_->addSpacing(5);
lytMain_->addLayout(lytInfo_);

this->setLayout(lytMain_);
}

InfoBox::~InfoBox()
{

}

////////////////////////////////////////////////////////////////////

////////////////////InfoBox.h///////////////////////////////////

#ifndef INFOBOX_H
#define INFOBOX_H

#include <QWidget>
#include <QObject>
#include <QLabel>
#include <QHBoxLayout>
#include <QVBoxLayout>


class InfoBox : public QWidget
{
public:
explicit InfoBox(QWidget *parent=0);
virtual ~InfoBox();

private:

QLabel lblTitle_;
QLabel lblImage_;
QLabel lblDuration_;

};

#endif // INFOBOX_H

/////////////////////////////////////////////////////////////////

/////////////////////InfoFlicker.cpp////////////////////////////

#include "infoflicker.h"

InfoFlicker::InfoFlicker(QWidget *parent)
{

scene = new QGraphicsScene;
scene->setItemIndexMethod(QGraphicsScene::NoIndex);
int w = 640;// - height
int h = 480;// - width

QWidget *pFlicker = new QWidget(this);

int iPosY = 0;

for (int i = 0; i < 10 ; ++i) {

pInfoBox_= new InfoBox();
pInfoBox_->resize(h, 150);
proxy = new QGraphicsProxyWidget;
proxy->setWidget(pInfoBox_);
scene->addItem(proxy);
proxy->setPos(0, iPosY);
proxy->resize(h, 150);
iPosY += 150;
}

scene->setItemIndexMethod(QGraphicsScene::BspTreeIndex);

canvas = new QGraphicsView(pFlicker);
canvas->setScene(scene);
canvas->setRenderHints(QPainter::TextAntialiasing);
canvas->setFrameShape(QFrame::NoFrame);
canvas->setFixedHeight(w);
canvas->show();

pFlicker->show();

flick= new FlickCharm;
flick->activateOn(canvas);
}

InfoFlicker::~InfoFlicker()
{

}


////////////////////////////////////////////////////////////////

////////////////////////InfoFlicker.h/////////////////////////

#ifndef INFOFLICKER_H
#define INFOFLICKER_H

#include <QObject>
#include <QWidget>
#include <QList>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsProxyWidget>
#include <flickcharm.h>
#include <infobox.h>

class InfoFlicker : public QWidget
{
public:
explicit InfoFlicker(QWidget *parent=0);
virtual ~InfoFlicker();

private:
QWidget *pInfoBoxHolder_;
InfoBox *pInfoBox_;
QGraphicsScene *scene;
QGraphicsView *canvas;
QGraphicsProxyWidget *proxy;

FlickCharm *flick;
};

#endif // INFOFLICKER_H

//////////////////////////////////////////////////////////////




for the FlickCharm, I used the code I found from this link http://qt.gitorious.org/qt-labs/graphics-dojo/trees/62d30fb38b7c5f5f900856ab225ddb0ed74138f3/flickcharm

sayuri
21st May 2010, 07:23
hey...i solved my problem.
i wrote the follwing function in flickcharm.cpp




void FlickCharm::moveToTop(QWidget *widget)
{
QAbstractScrollArea *scrollArea = dynamic_cast<QAbstractScrollArea*>(widget);
if (scrollArea)
{

QWidget *viewport = scrollArea->viewport();
FlickData *data = d->flickData.value(viewport);

QPoint topLeft = viewport->rect().topLeft();

setScrollOffset(data->widget,topLeft);
data->state = FlickData::Steady;

widget->update();
viewport->update();
}
}




And I called this funtion from InfoFlicker.cpp.
But it won't work properly when the infobox list is called for the first time. It will work next time when u update the infobox list.
I still don't know why this happen :confused:

suhailmohdmalik
10th August 2010, 12:14
i really hope that it will work...

aamer4yu
11th August 2010, 05:53
I guess the flickcharm example internallly uses QSlider for the sliding..
so why dont you set the value of QSlider simply to 0... :rolleyes: