PDA

View Full Version : dont want to scroll



maarvi
27th June 2011, 07:47
hello every one i want to ask that i have a main widget i which there are some buttons label list box etc and also 2 scroll areas in scroll area i show the graph. but as the name suggest that in scroll area my whole graph is not visible at one time. i want to show my whole graph at time in the same space means that graph must adjust to fit in that particular area what should i do some one suggest me QVBoxLayout but i don't find it in the tool list .

so far i have sone this


myplot * p = new myplot(gao.structpayloadgraph,gao1.structpayloadgr aph, gao.structcol-2, "payload");

myplot * p1 = new myplot(gao.structsessiongraph,gao.structsessiongra ph ,gao.structcol-2, "session");
p->resize(ui->scrollArea->size().width() ,ui->scrollArea->size().height());
p->show();
p1->resize(ui->scrollArea_2->size().width() ,ui->scrollArea_2->size().height());
p1->show();
ui->scrollArea->setWidget(p);
ui->scrollArea_2->setWidget(p1);


kindly help me i will be very thank full to you

Santosh Reddy
27th June 2011, 08:52
some one suggest me QVBoxLayout but .... You can use QVBoxLayout, or other Layout managers

i don't find it in the tool list What do you mean? QVBoxLayout is in Qt frame work.

maarvi
27th June 2011, 08:58
yes sir i have no idea how to use it. :( what should i do to solve my problem

Santosh Reddy
27th June 2011, 09:18
QLayout Documentation will be a good place to start from, please try the examples, if still find problem using it, forum is open
http://doc.qt.nokia.com/latest/examples-layouts.html

maarvi
27th June 2011, 09:25
thank u sir for your response but please tell me is there a way to remeove scrollbar and just show the complete picture at once

thanks

Santosh Reddy
27th June 2011, 09:29
don;t use QScrollBar, directly add the plot widget on to the main widget's layout, I can give you an example, fit this into you application


QHBoxLayout * layout = new QHBoxLayout;
mainWidget->setLayout(layout);

layout->addWidget(button); // adding button to layout
layout->addWidget(label); // adding label to layout
layout->addWidget(p1); // adding plot 1 to layout
layout->addWidget(p2); // adding plot 1 to layout

maarvi
27th June 2011, 09:50
sir i did


ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff) ;
ui-> scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOf f);
ui-> scrollArea->setWidgetResizable(false);


now my scrollbars are removed but now the problem is that my myplot object "p" is not taking the full space in scroll bar area. it is squeezed even though i wrote


p->resize(ui->scrollArea->size().width() ,ui->scrollArea->size().height());

what should i do to resize it

Santosh Reddy
27th June 2011, 09:55
it does not matter if you remove the scroll bars, you should remove the QScrollArea. Don't use QScrollArea at all, if your want your widgets to fit to the available space. Did you understand my example

maarvi
27th June 2011, 10:05
yes sir i got it thanks but i think i will need you help with the layout more. thanks

Santosh Reddy
27th June 2011, 10:19
Sure, you are welcome:)

maarvi
27th June 2011, 12:55
Sir i got an other problem i am calling all these statements in my button event handler like this

void analysis::on_pushButton_clicked()
{
myplot * p = new myplot(gao.structpayloadgraph,gao1.structpayloadgr aph, gao.structcol-2, "payload");

myplot * p1 = new myplot(gao.structsessiongraph,gao.structsessiongra ph ,gao.structcol-2, "session");


QHBoxLayout * layout = new QHBoxLayout;
ui->horizontalLayout_2->addLayout(layout);
layout->addWidget(p);
layout->addWidget(p1);
}

but the problem is that each time i click the button new graph appear and previous remains, like one !st click 2 appear on second they become 4 then 6......
how to i destroy QHBoxLayout in my button event handler

thanks

Santosh Reddy
27th June 2011, 13:07
Add this in the beginning of the slot (i assume ui->horizontalLayout_2 does not have anything else, other than the layout you add)


void analysis::on_pushButton_clicked()
{
QLayoutItem *child;
while ((child = ui->horizontalLayout_2->takeAt(0)) != 0) {
delete child;
}

....
}

maarvi
27th June 2011, 13:19
thank u so much sir for your help

Added after 5 minutes:

sir the previous on is still not removing now graph is drawn over one an other

ChrisW67
27th June 2011, 23:09
See your other thread: http://www.qtcentre.org/threads/42750-destroy-QHBoxLayout

Please refrain from asking the same question in multiple places.