Home » » Resize problem in scroll area

Resize problem in scroll area


Hello everyone, here is my code:
myplot *p = new myplot(gao.structpayloadgraph, 
                       gao1.structpayloadgraph, 
                       gao.structcol-2, "payload");

ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
ui->scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
ui->scrollArea->setWidgetResizable(false);
p->resize(ui->scrollArea->size().width(), ui->scrollArea->size().height());

ui->scrollArea->setWidget(p);

-----Question-----

I want p to take up the full available space of the 
scrollbar area and fit itself. However, the appearance looks 'squeezed' 
even though I called the resize function. What should I do to achieve 
the desired effect? 

-----Answers-----

1.
You have to treat the scroll area content widget as a normal QWidget. If you want automatic resize and you must use layouts in Qt. Try the following :
QVBoxLayout layout = new QVBoxLayout( ui->scrollAreaContent);
layout->setMargin(0);
layout->setContentsMargins(0,0,0,0);
layout->setSpacing(0);
ui->scrollAreaContent->setLayout( layout);
layout->addWidget(p);
NOTE: ui->scrollAreaContent is a guess, but I think you are using ui files and default content widget is named like that ...
2.
Go to the top right of the QT creator designer screen (Object, Class), right click on the QScrollArea row and select the "Lay Out" menu item, choose a layout (eg vertical or horizontal layout), make sure that your QWidget has a minimum or above size policy. Your scroll widget should now resize with the layout. 



0 nhận xét:

Post a Comment

Popular Posts

Powered by Blogger.