qt - How to create a scrollable widget using QHBoxLayout and QScrollArea -


i trying create widget scrollable using qhboxlayout , qscrollarea unable succeed create gui,here code can 1 please suggest me need change. appreciated

mainlayout = new qhboxlayout(this); mainlayout->setsizeconstraint(qlayout::setmaximumsize); qcheckbox *sam_box = new qcheckbox(this); sam_box->settext("haiiiiiiiiiii"); sam_box->setfixedsize(10000,10000); qcheckbox *so_box = new qcheckbox(this); so_box->settext("howwwwwwwwwwww"); so_box->setfixedsize(150000,15000); mainlayout->addwidget(sam_box); mainlayout->addwidget(so_box);  qscrollarea *scrollarea = new qscrollarea(this); scrollarea->setbackgroundrole(qpalette::shadow); scrollarea->setfixedsize(700,500); scrollarea->setlayout(mainlayout);` 

here output screen

thanks in advance, rohith.g

one way achieve below logic centralwidget() -> qhboxlayout-> qscrollarea -> qwidget-> add check box

the code flow & comments explain logic in detail.

qwidget *wgt = new qwidget();//new code     wgt->setgeometry(0,0,500,500); //new code     //qhboxlayout mainlayout = new qhboxlayout(this);     qhboxlayout *mainlayout = new qhboxlayout(this->centralwidget());      mainlayout->setsizeconstraint(qlayout::setmaximumsize);     //qcheckbox *sam_box = new qcheckbox(this);     qcheckbox *sam_box = new qcheckbox(wgt);     sam_box->settext("haiiiiiiiiiii");      //sam_box->setfixedsize(10000,10000);     sam_box->setfixedsize(200,200); //make small quick testing      //qcheckbox *so_box = new qcheckbox(this);     qcheckbox *so_box = new qcheckbox(wgt);     so_box->settext("howwwwwwwwwwww");      //so_box->setfixedsize(150000,15000);     so_box->setfixedsize(150,150); //make small quick testing      //mainlayout->addwidget(sam_box);     //mainlayout->addwidget(so_box);      qscrollarea *scrollarea = new qscrollarea();     scrollarea->setbackgroundrole(qpalette::shadow);     //scrollarea->setfixedsize(700,500); //scroll area cant resized     mainlayout->addwidget(scrollarea); //new code     //scrollarea->setlayout(mainlayout);     scrollarea->setwidget(wgt); 

enter image description here

below code generate 30 qcheckboxes added each ten in vertical box layout , vertical layout in horizontal box layout

qscrollarea *scrl = new qscrollarea();     scrl->setgeometry(0,0,300,300);     qwidget *wgtmain = new qwidget();     qhboxlayout *hboxmain = new qhboxlayout(wgtmain);     for(int icount=0;icount<3;icount++){         qwidget *wgtsub = new qwidget();         qvboxlayout *vboxsub = new qvboxlayout(wgtsub);         for(int jcount=0;jcount<10;jcount++){             qcheckbox *chk = new qcheckbox("check box " + qstring::number(jcount+1) + " of " + qstring::number(icount+1));             vboxsub->addwidget(chk);         }         hboxmain->addwidget(wgtsub);     }     scrl->setwidget(wgtmain);     scrl->show(); 

enter image description here


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -