如何在 Qt 中创建带有 float 工具栏的QDialog
?
QMainWindow
的附件作为 QDialog
中的小部件是不合适的。
最佳答案
为什么不合适?以下代码就像魅力一样。
#include <QtGui>
class MyDialog : public QDialog
{
Q_OBJECT
public:
MyDialog(QWidget* parent=0)
{
QMainWindow* child = new QMainWindow;
QLabel* label = new QLabel(tr("QMainWindow with toolbar!"));
label->setAlignment(Qt::AlignCenter);
child->setCentralWidget(label);
QToolBar* toolbar = child->addToolBar(tr("Tool"));
toolbar->addAction(tr("Test"), this, SLOT(doTest()));
QHBoxLayout* layout = new QHBoxLayout(this);
layout->setContentsMargins(0,0,0,0);
layout->addWidget(child);
}
private slots:
void doTest()
{
QMessageBox::information(this, tr("Test"), tr("ToolBar is Working!"));
}
};
关于qt - 带有 float 工具栏的 QDialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12927205/