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
TimeSelection Widget.png

This is max vertical shrink
TimeSelection_Vertical Resize limit.png

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.
Desired_TimeSelection.png

Qt Code:
  1. CTimeSelect::CTimeSelect(QWidget *parent)
  2. : QWidget(parent)
  3. {
  4. this->setLayout(&lyt);
  5. this->setContentsMargins(0, 0, 0, 0);
  6. lyt.setSpacing(0);
  7. lyt.setContentsMargins(0, 0, 0, 0);
  8. onInit();
  9. }
  10.  
  11. CTimeSelect::~CTimeSelect()
  12. {
  13. }
  14.  
  15. void CTimeSelect::onInit()
  16. {
  17. timeDisp.setText("11:30");
  18.  
  19. timeDisp.setFont(QFont("Lucida Console", 24, QFont::Bold, false));
  20. timeDisp.setReadOnly(true);
  21. timeDisp.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  22. timeDisp.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  23. timeDisp.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  24.  
  25. timeUp.setText("+");
  26. timeUp.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  27. timeDown.setText("-");
  28. timeDown.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  29.  
  30. am_pm.setText("PM");
  31. am_pm.setReadOnly(true);
  32. am_pm.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  33. am_pm.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  34. am_pm.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  35.  
  36. am.setText("^");
  37. am.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  38. pm.setText("v");
  39. pm.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  40.  
  41. lyt.addWidget(&timeDisp, 0, 0, 2, 4);
  42. lyt.addWidget(&timeUp, 0, 4, 1, 1);
  43. lyt.addWidget(&timeDown, 1, 4, 1, 1);
  44. lyt.addWidget(&am_pm, 0, 5, 2, 2);
  45. lyt.addWidget(&am, 0, 7, 1, 1);
  46. lyt.addWidget(&pm, 1, 7, 1, 1);
  47.  
  48. lyt.setColumnStretch(0, 1);
  49. lyt.setColumnStretch(4, 0);
  50. lyt.setColumnStretch(5, 1);
  51. lyt.setColumnStretch(7, 0);
  52.  
  53. }
To copy to clipboard, switch view to plain text mode 

Please help me solve this issue. Thank you.