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;
QFrame *hor_line = new QFrame();
hor_line->setFrameShape( QFrame::HLine );
QVBoxLayout *layout = new QVBoxLayout();
layout->addWidget( hor_line );
Table = new QTableView(this);
temp = Table;
t = new TableLayout(statInfoWidget);
// if(num_version == 1)
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);");
QSizePolicy policy = Table->sizePolicy();
Any help, please?
Try set horizontal and vertical policy:
I've tired both for the Table, both "expanding" as well as "MinimumExpanding".
Neither seems to work.
What is Static_Info,TableLayout? Can you post part of code as project somewhere if it is small?
[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
I thing using frames and inserting ur widgets in frames and setting policy to frame will resolve.
[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.
Hi .. starbearer try this code its working fine in my code
QSizePolicy sizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
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...
But this had the same effect.