如何在Qt中创建带浮动工具栏的QDialog?
在QDialog中附加带有工具栏作为小部件的QMainWindow是不合适的。
发布于 2012-10-17 15:49:22
为什么不合适呢?下面的代码就像charm一样。
#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!"));
}
};发布于 2014-06-25 19:41:18
看看Can you add a toolbar to QDialog?,试着像这样写smth
myDialog->layout()->setMenuBar(myToolBar);https://stackoverflow.com/questions/12927205
复制相似问题