PDA

View Full Version : making tab width size smaller



Alex22
14th December 2015, 19:30
hi,
i have wrote under code. while clicking on button4 (ok) 2 editlines will be invisiable. when those. are invisiable, i need tab be smaller and fit to the pushbuttons instead of pushbuttons be larger. thanks for any help





#include "mainwindow.h"

#include <QApplication>
#include <QWidget>
#include <QLineEdit>
#include <QCheckBox>
#include <QTabWidget>
#include <QPushButton>
#include <QGridLayout>


int main(int argc, char *argv[])
{
QApplication a(argc, argv);
//MainWindow w;
//w.show();
QWidget qwd;
QWidget t1;
QTabWidget tab(&qwd);
tab.addTab(&t1,"tab");

QGridLayout gl_tab(&t1);
QGridLayout gl_qwd(&qwd);

QPushButton p1(&t1);
QPushButton p2(&t1);
QLineEdit l1(&t1);
QLineEdit l2(&t1);
gl_tab.addWidget(&l1,0,0);
gl_tab.addWidget(&l2,1,0);
gl_tab.addWidget(&p1,0,1);
gl_tab.addWidget(&p2,1,1);
l1.setVisible(1);
l2.setVisible(1);


QPushButton p3(&qwd);

QPushButton p4(&qwd);
p4.setText("ok");

QPushButton p5(&qwd);

gl_qwd.addWidget(&tab,0,0,1,1);
gl_qwd.addWidget(&p3,0,1,1,1);
gl_qwd.addWidget(&p4,1,0,1,1);
gl_qwd.addWidget(&p5,1,1,1,1);

QObject::connect(&p4, SIGNAL(clicked(bool)), &l1, SLOT(setVisible(bool)));
QObject::connect(&p4, SIGNAL(clicked(bool)), &l2, SLOT(setVisible(bool)));

qwd.show();
return a.exec();
}

anda_skoa
15th December 2015, 09:57
You can try resizing the widget to its sizeHint() or even resizing to 0,0 and let the layout expand it again as necessary.

Cheers,
_