rawfool
18th April 2013, 09:16
Hi,
I'm facing difficulties in setting QSizePolicy to my widgets in QGridLayout.
I'm creating a custom time-selection widget, that has 2 QTextEdit, 4 buttons. My problem is the QTextEdit widgets and QPushButtons are not shrinking as desired.
PFB, the screenshot of the Timeselection Widget that I'm trying to develop -
This is max horizontal shrink
8960
This is max vertical shrink
8961
Desired behaviour -
I need the horizontal shrink to be limited to text in QTextEdit without wrapping text(displaying in next line). And I need the vertical size to shrink upto row-end of the text.
Here the buttons are also not shrinking beyond the one I showed in 1st image. I need the buttons to be as small as possible.
As shown in the pic below, I need the exact idea to be translated to my widgets behavior.
8962
CTimeSelect::CTimeSelect(QWidget *parent)
: QWidget(parent)
{
this->setLayout(&lyt);
this->setContentsMargins(0, 0, 0, 0);
lyt.setSpacing(0);
lyt.setContentsMargins(0, 0, 0, 0);
onInit();
}
CTimeSelect::~CTimeSelect()
{
}
void CTimeSelect::onInit()
{
timeDisp.setText("11:30");
timeDisp.setFont(QFont("Lucida Console", 24, QFont::Bold, false));
timeDisp.setReadOnly(true);
timeDisp.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
timeDisp.setHorizontalScrollBarPolicy(Qt::ScrollBa rAlwaysOff);
timeDisp.setVerticalScrollBarPolicy(Qt::ScrollBarA lwaysOff);
timeUp.setText("+");
timeUp.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
timeDown.setText("-");
timeDown.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
am_pm.setText("PM");
am_pm.setReadOnly(true);
am_pm.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
am_pm.setHorizontalScrollBarPolicy(Qt::ScrollBarAl waysOff);
am_pm.setVerticalScrollBarPolicy(Qt::ScrollBarAlwa ysOff);
am.setText("^");
am.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
pm.setText("v");
pm.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
lyt.addWidget(&timeDisp, 0, 0, 2, 4);
lyt.addWidget(&timeUp, 0, 4, 1, 1);
lyt.addWidget(&timeDown, 1, 4, 1, 1);
lyt.addWidget(&am_pm, 0, 5, 2, 2);
lyt.addWidget(&am, 0, 7, 1, 1);
lyt.addWidget(&pm, 1, 7, 1, 1);
lyt.setColumnStretch(0, 1);
lyt.setColumnStretch(4, 0);
lyt.setColumnStretch(5, 1);
lyt.setColumnStretch(7, 0);
}
Please help me solve this issue. Thank you.
I'm facing difficulties in setting QSizePolicy to my widgets in QGridLayout.
I'm creating a custom time-selection widget, that has 2 QTextEdit, 4 buttons. My problem is the QTextEdit widgets and QPushButtons are not shrinking as desired.
PFB, the screenshot of the Timeselection Widget that I'm trying to develop -
This is max horizontal shrink
8960
This is max vertical shrink
8961
Desired behaviour -
I need the horizontal shrink to be limited to text in QTextEdit without wrapping text(displaying in next line). And I need the vertical size to shrink upto row-end of the text.
Here the buttons are also not shrinking beyond the one I showed in 1st image. I need the buttons to be as small as possible.
As shown in the pic below, I need the exact idea to be translated to my widgets behavior.
8962
CTimeSelect::CTimeSelect(QWidget *parent)
: QWidget(parent)
{
this->setLayout(&lyt);
this->setContentsMargins(0, 0, 0, 0);
lyt.setSpacing(0);
lyt.setContentsMargins(0, 0, 0, 0);
onInit();
}
CTimeSelect::~CTimeSelect()
{
}
void CTimeSelect::onInit()
{
timeDisp.setText("11:30");
timeDisp.setFont(QFont("Lucida Console", 24, QFont::Bold, false));
timeDisp.setReadOnly(true);
timeDisp.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
timeDisp.setHorizontalScrollBarPolicy(Qt::ScrollBa rAlwaysOff);
timeDisp.setVerticalScrollBarPolicy(Qt::ScrollBarA lwaysOff);
timeUp.setText("+");
timeUp.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
timeDown.setText("-");
timeDown.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
am_pm.setText("PM");
am_pm.setReadOnly(true);
am_pm.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
am_pm.setHorizontalScrollBarPolicy(Qt::ScrollBarAl waysOff);
am_pm.setVerticalScrollBarPolicy(Qt::ScrollBarAlwa ysOff);
am.setText("^");
am.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
pm.setText("v");
pm.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
lyt.addWidget(&timeDisp, 0, 0, 2, 4);
lyt.addWidget(&timeUp, 0, 4, 1, 1);
lyt.addWidget(&timeDown, 1, 4, 1, 1);
lyt.addWidget(&am_pm, 0, 5, 2, 2);
lyt.addWidget(&am, 0, 7, 1, 1);
lyt.addWidget(&pm, 1, 7, 1, 1);
lyt.setColumnStretch(0, 1);
lyt.setColumnStretch(4, 0);
lyt.setColumnStretch(5, 1);
lyt.setColumnStretch(7, 0);
}
Please help me solve this issue. Thank you.