why does QTableView expand to cover the buttons
I did this program outside Eclipse(with built in Qt4)
and inside Eclipse.
Outside Eclipse, the table view is its own "dialog" OK!
Scroll bars show up perfectly!
Inside Eclipse the tableview shares a dialog with two buttons:
(1) show table(from MySQL database)
(2) close
When I hit the button "show table" the table shows in the table view but covers the two buttons.
Using grid layout, the buttons are on top of the table view.
Scroll bars work! I tried vertical and horizontal layout even with spacers!
I inserted the table view into a frame and the problem is solved except that there are no scrollbars!
I did try using the qt designer OUTSIDE Eclipse!
Why does the table view flood the dialog?
Code:
// querymodel.h
#ifndef QUERYMODEL_H
#define QUERYMODEL_H
#include <QMessageBox>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
#include <QSqlQueryModel>
#include <QSqlTableModel>
#include <QtDebug>
#include <QtGui/QWidget>
#include "ui_querymodel.h"
{
Q_OBJECT
public:
~querymodel();
public slots:
void showTable();
private:
Ui::querymodelClass ui;
};
#endif // QUERYMODEL_H
Code:
// querymodel.cpp
#include "querymodel.h"
querymodel
::querymodel(QWidget *parent
){
ui.setupUi(this);
connect( ui.pushButtonShowTable, SIGNAL(clicked()), this, SLOT(showTable()) );
}
querymodel::~querymodel()
{
delete model;
}
void querymodel::showTable()
{
db.setHostName("localhost");
db.setDatabaseName("landonx");
db.setUserName("landon4");
db.setPassword("3141");
db.
setConnectOptions(QString("CLIENT_INTERACTIVE"));
bool ok = db.open();
model->setTable( "log_book" );
model->select();
model
->setHeaderData
( 0, Qt
::Horizontal,
QObject::tr("rowid") );
model
->setHeaderData
( 1, Qt
::Horizontal,
QObject::tr("fdate") );
model
->setHeaderData
( 2, Qt
::Horizontal,
QObject::tr("acid") );
model
->setHeaderData
( 3, Qt
::Horizontal,
QObject::tr("actype") );
model
->setHeaderData
( 4, Qt
::Horizontal,
QObject::tr("nlandings") );
model
->setHeaderData
( 5, Qt
::Horizontal,
QObject::tr("nhours") );
// QTableView *view = new QTableView();
ui.tableView->setModel( model );
ui.tableView->setAlternatingRowColors ( true );
ui.tableView->setFixedSize ( 800,500 );
ui.tableView->show();
}
Re: why does QTableView expand to cover the buttons
The problem is in the .ui file, so the code you have posted is completely irrelevant. Do you have a top-level layout for all container widgets?
Re: why does QTableView expand to cover the buttons
here is querymodel.ui
2 buttons and a table view
Code:
<ui version="4.0" >
<class>querymodelClass</class>
<widget class="QWidget" name="querymodelClass" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>698</width>
<height>561</height>
</rect>
</property>
<property name="maximumSize" >
<size>
<width>16776957</width>
<height>16777215</height>
</size>
</property>
<property name="windowTitle" >
<string>querymodel</string>
</property>
<widget class="QPushButton" name="pushButtonClose" >
<property name="geometry" >
<rect>
<x>10</x>
<y>450</y>
<width>83</width>
<height>30</height>
</rect>
</property>
<property name="text" >
<string>Close</string>
</property>
</widget>
<widget class="QPushButton" name="pushButtonShowTable" >
<property name="geometry" >
<rect>
<x>10</x>
<y>410</y>
<width>83</width>
<height>30</height>
</rect>
</property>
<property name="text" >
<string>Show Table</string>
</property>
</widget>
<widget class="QTableView" name="tableView" >
<property name="geometry" >
<rect>
<x>10</x>
<y>20</y>
<width>271</width>
<height>201</height>
</rect>
</property>
<property name="verticalScrollBarPolicy" >
<enum>Qt::ScrollBarAlwaysOn</enum>
</property>
<property name="horizontalScrollBarPolicy" >
<enum>Qt::ScrollBarAlwaysOn</enum>
</property>
</widget>
</widget>
<layoutdefault spacing="6" margin="11" />
<resources/>
<connections>
<connection>
<sender>pushButtonClose</sender>
<signal>clicked()</signal>
<receiver>querymodelClass</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel" >
<x>391</x>
<y>274</y>
</hint>
<hint type="destinationlabel" >
<x>348</x>
<y>227</y>
</hint>
</hints>
</connection>
</connections>
</ui>
Re: why does QTableView expand to cover the buttons
Well, you don't have any layouts in this .ui file. To add a top-level layout you have to click on the form's background and then click on of the "Lay out in ..." buttons.
Re: why does QTableView expand to cover the buttons
Quote:
Originally Posted by
landonmkelsey
I wonder what the widgets on the left (same selections as right clicking the form background) are for and how one would use those widgets
These are for creating nested layouts and you can't create a top-level layout using them.