qt - 带有 float 工具栏的 QDialog

标签 qt toolbar qdialog

如何在 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/

相关文章:

qt - Qt 中的 PDF 查看器

qt - Qt 中是否有可折叠面板的标准组件?

java - 如何右对齐 Java SWT Unified ToolBar (OS X) 中的搜索栏

qt - 仅将非模态 QDialog 窗口放置在我的应用程序顶部,而不是所有应用程序顶部

c++ - QWidget失去了它的 parent

python - 如何在没有用户交互的情况下显示模式 QDialog?

c++ - 如何在qt中获取QModelIndexList中的值?

android - 如何使 DrawerLayout 显示在工具栏下方?

eclipse-rcp - eclipse RCP : Right aligned search field in toolbar

windows - 有没有办法在 Windows 上使用 Qt 列出当前进程?