PDA

View Full Version : Getting TableView to strech with Dialog



db
20th November 2007, 16:00
I'm creating a simple Dialog which contains a TableView. What I'm having problems with is:
1) getting the TavleView to expand to the size of the model and there by expand the size of the Dialog and
2) getting the TableView to strech as the Dialog box is enlarged.

I used Designer to create the object. I created a Dialog without buttons. Placed a vertical layout in it and place a tableview within the vertical layout. Nothing else.

I use the following code to display it but I can't get the desired effects. I tried the setSizeConstraint (I found in another example) but it just shrinks the TableView. The resize seems to have no affect.

Does anyone have a suggestion? Thanks


#include <QDialog>
#include <QTableView>

#include "ui_View.h"

//-----------------------------------------------------------------------------------

class CViewInputs : public QDialog, public Ui::CView
{
Q_OBJECT

public:
// CViewInputs : class constructor method
CViewInputs(QWidget *parent = 0, CHostIFTools * tools=0);

// ~CViewInputs : class destrcutor method
~CViewInputs();

private slots:

protected:
};


//-----------------------------------------------------------------------------------

CViewInputs::CViewInputs(QWidget *parent)
: QDialog(parent)
{
// create form
setupUi(this);

// setup so that form is removed when closed
setAttribute(Qt::WA_DeleteOnClose);

// vboxLayout->setSizeConstraint(QLayout::SetFixedSize);

// setup model
model.setColumnCount(6);
model.setRowCount(4);

// tableView->resize(500,300);

// add data to model
item = new QStandardItem( "Packet Counter");
model.setItem(0,0,item);
item = new QStandardItem( QString::number(200) );
model.setItem(0,1,item);
item = new QStandardItem( "Packets Missed");
model.setItem(0,2,item);
item = new QStandardItem( QString::number(10) );
model.setItem(0,3,item);

// assign model to view
tableView->setModel( &model );

}

DeepDiver
20th November 2007, 17:30
You need to define a layout.
Look at this:
http://doc.trolltech.com/4.3/layout.html
http://doc.trolltech.com/4.3/designer-designing-a-component.html#creating-a-layout

db
20th November 2007, 18:09
Actually I have defined a layout. As I said, with the designer I placed a vertical layout object on the dialog and then inserted the table view into the layout. Is there a command where I assign the layout to the dialog??

DeepDiver
20th November 2007, 18:14
Right mouse button click on the dialog.
From the context menu choose grid layout.

Good luck!

db
20th November 2007, 20:47
Grid layout has no differnet affect than vertical layout.