QFiledialog添加控件

一种方法(我使用的):

http://www.cnblogs.com/foohack/p/3914164.html。至于点击按钮窗口关闭的问题:使用信号去连接一个自己的槽。


另一种方法(担心Qt升级导致要重新修改代码,没有使用):

QFileDialog* f = new QFileDialog();
	f->setOption(QFileDialog::DontUseNativeDialog, true);

	QGridLayout *layout = static_cast<QGridLayout*>(f->layout());

	QList< QPair<QLayoutItem*, QList<int> > > moved_items;
	f->show();
	for (int i = 0; i < layout->count(); i++) {
		int row, column, rowSpan, columnSpan;
		layout->getItemPosition(i, &row, &column, &rowSpan, &columnSpan);
		if (row >= 2) {
			QList<int> list;
			list << (row + 1) << column << rowSpan << columnSpan;
			moved_items << qMakePair(layout->takeAt(i), list);
			i--; // takeAt has shifted the rest items
		}
	}

	for (int i = 0; i < moved_items.count(); i++) {
		layout->addItem(moved_items[i].first,
			moved_items[i].second[0],
			moved_items[i].second[1],
			moved_items[i].second[2],
			moved_items[i].second[3]);
	}

	QLineEdit *line = new QLineEdit();
	layout->addWidget(line, 2, 0, 1, 4);


你可能感兴趣的:(QFiledialog添加控件)