QT细节列表

# 设置控件在QGridLayout的位置

以QGridLayout的左上角为原点,第一个参数表示距原点的高度为0,第二个参数表示距原点的水平距离为5
bottomLayout->addWidget(upButton, 0, 5);

 

# 设置窗口启动时最大化

MainWindow *m=new MainWindow;
m->showMaximized();

 

# 使用代理model,让QTableView实现行列互换

rotatedproxymodel.h

#include <QAbstractProxyModel>
class RotatedProxyModel : public QAbstractProxyModel
{
public:
	RotatedProxyModel(QObject *p = 0) : QAbstractProxyModel(p){}
	QModelIndex mapFromSource ( const QModelIndex & sourceIndex ) const
	{
		return index(sourceIndex.column(), sourceIndex.row());
	}
	QModelIndex mapToSource ( const QModelIndex & proxyIndex ) const
	{
		return sourceModel()->index(proxyIndex.column(), proxyIndex.row());
	}
	QModelIndex index(int r, int c, const QModelIndex &ind=QModelIndex()) const
	{
		return createIndex(r,c);
	}
	QModelIndex parent(const QModelIndex&) const 
	{
		return QModelIndex();
	}
	int rowCount(const QModelIndex &) const
	{
		return sourceModel()->columnCount();
	}
	int columnCount(const QModelIndex &) const
	{
		return sourceModel()->rowCount();
	}
	QVariant data(const QModelIndex &ind, int role) const 
	{
		return sourceModel()->data(mapToSource(ind), role);
	}
	QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const
	{
		if( orientation == Qt::Horizontal )
			return sourceModel()->headerData( section, Qt::Vertical, role );
		else
			return sourceModel()->headerData( section, Qt::Horizontal, role );
	}

	bool setHeaderData( int section, Qt::Orientation orientation, const QVariant & value, int role = Qt::DisplayRole )
	{
		if( orientation == Qt::Horizontal )
			return sourceModel()->setHeaderData( section, Qt::Vertical, value, role );
		else
			return sourceModel()->setHeaderData( section, Qt::Horizontal, value, role );
	}
};

 使用方法:

standardView = new QTableView;
QSqlTableModel *sourceModel = new QSqlTableModel;
sourceModel->setTable("model_group");
sourceModel->select();
sourceModel->setEditStrategy(QSqlTableModel::OnRowChange);
standardModel = new RotatedProxyModel;
standardModel->setSourceModel(sourceModel);
standardView->setModel(standardModel);
 

# 获取屏幕大小

屏幕大小:
QApplication::desktop().size()
单独的高和宽:
QApplication::desktop().height()
QApplication::desktop().width()

 

# MySql返回上次insert操作后生成的id

select LAST_INSERT_ID()

你可能感兴趣的:(C++,c,mysql,C#,qt)