QTableView not expanding/reducing when QMainWindow is resized
-
I have a QMainWindow.
Inside the QMainWindow, I have a central widget.
For the central widget, I have a QVBoxLayout.
To this QVBoxLayout, I've added 3 widgets. One is a widget with some labels, which has a QGridLayout. The other is a horizontal line.
The third is a QTableView. The problem is that when I try and expand the QMainWwindow, despite whatever resize policy I set ( or not), the TableView does not expand, and it leaves an ungainly blank area in the rest of the expanded QMainWindow.
Could anyone tell me how I can make the table expand/resize when the Window is resized.
Here is the relevant code
@
statInfoWidget = new Static_Info(TagN);
QWidget *widget = new QWidget;
setCentralWidget(widget);
QFrame *hor_line = new QFrame();
hor_line->setFrameShape( QFrame::HLine );
QVBoxLayout *layout = new QVBoxLayout();
layout->setMargin(2);layout->addWidget(statInfoWidget);
layout->addWidget( hor_line );
Table = new QTableView(this);
temp = Table;
t = new TableLayout(statInfoWidget);
Table->setModel(t);
Table->verticalHeader()->hide();
Table->horizontalHeader()->hide();
Table->setShowGrid(false);
Table->setContextMenuPolicy(Qt::CustomContextMenu);
//Table->setColumnWidth(2,290);
// Table->setColumnWidth(0,25);
// if(num_version == 1)
// Table->setColumnWidth(1,0);
// else
// Table->setColumnWidth(1,43);
// Table->setColumnWidth(3,210);
// Table->setColumnWidth(4,170);
// Table->setColumnWidth(5,50);
statInfoWidget->setStyleSheet("background: rgb(153,185,193);color:rgb(0,0,0); font-family:Tahoma;font-size:19px; border: 0px outset rgb(255,255,255);gridline-color: #669933;"
"selection-background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #486909, stop: 1 white);");
Table->setStyleSheet("background: rgb(153,185,193);color:rgb(0,0,0); font-family:Tahoma;font-size:15px; font-weight:bold; border: 0px outset rgb(255,255,255);gridline-color: #669933;"
"selection-background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 transparent, stop: 1 white);");
// layout->addWidget(button1);
QSizePolicy policy = Table->sizePolicy();
policy.setVerticalStretch(1);
policy.setHorizontalStretch(1);
Table->setSizePolicy(policy);
layout->addWidget(Table);
widget->setLayout(layout);
@Kindly advise.Thanks.
-
Any help, please?
-
I've tired both for the Table, both "expanding" as well as "MinimumExpanding".
Neither seems to work.
-
[quote author="qxoz" date="1362984243"]What is Static_Info,TableLayout? Can you post part of code as project somewhere if it is small?[/quote]
Static_Info is a simple QWidget, which has a few QLabels as content, and is set in a QGridLayout.
@
class Static_Info : public QWidget
@TableLayout is a class derived from QAbstractTableModel.
@
class TableLayout : public QAbstractTableModel
@ -
[quote author="devfeel" date="1362986724"]I thing using frames and inserting ur widgets in frames and setting policy to frame will resolve.[/quote]
Could you develop your point, please?
And the problem is only with QTableView. The other widgets which I've added to QVBoxLayout of the central widget, they expand fine.
-
Kindly advise.
-
Hi .. starbearer try this code its working fine in my code
@
QSizePolicy sizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(Table->sizePolicy().hasHeightForWidth());
Table->setSizePolicy(sizePolicy);
@Edit: code goes between @ tags, please; Andre
-
Table gets expanded, but unfortunately, it overrides any size which I may have used for my columns.
I've set a fixed size for my columns( It's commented out in the code above)....but I need that size.
If I use the above method, then all the fixed size for columns gets overriden, and all columns get an equal size.
Any way, I can have the columns of a size ( to show the contents in full), and manage to resize the table as well?
I tried this...
@
Table->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
@But this had the same effect.
Kindly advise...thanks.