qt - 带有 float 工具栏的 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!"));
    }
};

https://stackoverflow.com/questions/12927205/

相关文章:

perl - 在 Dancer 中使用 Hooks 修改异常处理

maven - 从 Java 类路径加载 JRuby 脚本

hibernate - 带有关联表的 JPA 注解

Django 模型 - 共享公共(public)基类的不同对象类型的外键

php - DOMDocument::save[domdocument.save]:无法打开流:权限

python - Python 中的伪随机二进制序列 (prbs)

heroku - 如何在 Heroku bash 或 Heroku Scheduler 中实现 He

c# - PDFSharp 使用 PdfTextField 作为位置和大小引用在 pdf 中插入图像

python - 故意在python中制作一个孤儿进程

asp.net - 如何允许在 TinyMCE 中嵌入内联标签