PDA

View Full Version : window crazing



yuvaraj.yadav
5th May 2009, 18:59
Hi

I hope you people will encourage me...

Still I am reading the documents ... At same time trying with sample programs...

Already Wysto told me don't use the list view to add widgets.... I don't use here after...

Sorry , I am learning slowly....here i have been trying one small sample application

Nothing displaying the Tweets...I displayed tweets in listview with somebody help..

Here i am using the Event methods to get the current window position...and i assign the width to my tweet..

please see my code.

To display the tweet



QStandardItemModel * model = new QStandardItemModel(this);
for (int i = 0; i < 21; ++i)
{
QStandardItem * item = new QStandardItem;
model->appendRow(item);
}
ui->listView->setModel(model);
for (int i = 0; i < 21; ++i)
{ Tweet * t = new Tweet(this);
t->resize(ui->listView->size().width(), t->size().height());
qDebug("width:%d",ui->listView->size().width());
qDebug("Height:%d", t->size().height());
model->item(i)->setSizeHint(t->size());
ui->listView->setIndexWidget(model->item(i)->index(), t);
}
}


my event function



void MainWindow::resizeEvent( QResizeEvent *event )
{
emit resizeView( event->size().width(), event->oldSize().width() );
}


this one emit the resizeView and call the resizeData slot...

My slot code is

void MainWindow ::resizeData(int width, int oldWidth)
{

qDebug("current width:%d and old width : %d", width,oldWidth);

QSize itemSize;
Tweet *aTweet;
for ( int i = 0; i < 21; i++ ) {
aTweet = t;
aTweet->resize( width , aTweet->size().height() );
itemSize = model->item(i)->sizeHint();
itemSize.rwidth() += width - oldWidth;
itemSize.rheight() = aTweet->size().height();
model->item(i)->setSizeHint( itemSize );
}
}




here i resized my tweet width according to the window width....

If i try to modify the window window size, the window is crazed(closed)...




Please help me to solve this issue

Lykurg
5th May 2009, 19:06
Already Wysto told me don't use the list view to add widgets.... I don't use here after...

He is called wysota and it looks like it's not enough for you that he told you to better use QListWidget. So I by myself tell you to use QListWidget. Even if I don't know what your problem is but for a bloody rookies that would be the best start. And by the way: this is the 7th thread always about the same topic...

yuvaraj.yadav
5th May 2009, 19:15
I don't have any sources to get help except Qtforum, whats why i posted.

wysota
6th May 2009, 10:15
I have to finally ask this question - what is the base class for "Tweet"?

faldzip
6th May 2009, 10:30
I don't have any sources to get help except Qtforum, whats why i posted.
You have. Just open Qt Assistant and Qt Examples & Demos

yuvaraj.yadav
6th May 2009, 10:41
QWidget is the base class for Tweet class

wysota
6th May 2009, 11:45
QWidget is the base class for Tweet class

So why do you keep trying to push the widget to the list view? Why don't you use QScrollArea as I suggested a few times before?


QScrollArea *sa = new QScrollArea;
QWidget *viewport = new QWidget;
QVBoxLayout *l = new QVBoxLayout(viewport);
sa->setWidget(viewport);
sa->setWidgetResizable(true);
for(int i = 0; i<10; i++){
l->addWidget(new Tweet);
}

yuvaraj.yadav
6th May 2009, 12:14
Our team asked me to use the list view only. thats why. Already we have worked in mobile side

ok i have asked one issue regarding the resize problem...How do i solve that one.... I am getting problem,While i am trying to modify the tweet width with window current width...


please help me.


Thanks

Yuvaraj R

wysota
6th May 2009, 15:56
Our team asked me to use the list view only.
In that case implement a delegate for your list instead of a widget.


ok i have asked one issue regarding the resize problem...How do i solve that one.... I am getting problem,While i am trying to modify the tweet width with window current width...
That has to be done through the delegate as well so better instead of doing crazy things, do it properly - implement a delegate showing the tweet.