你能添加一个工具栏到QDialog吗? [英] Can you add a toolbar to QDialog?

查看:1870
本文介绍了你能添加一个工具栏到QDialog吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个项目,需要调用一个模态窗口与工具栏,在一些数据加载之前做一些工作。我需要工具栏的原因是用户有几个不同的可能选项可以组合。

I'm working on a project that needs to call a modal window with a toolbar to do some work on some data before it's loaded. The reason I need the toolbar is the user has a few different possible options that can be combined.

这里显而易见的选择是一个模态对话框(我现在工作)。问题是我想要一个工具栏。这是一个两部分问题:

The obvious choice here is a Modal dialog (which I have working right now). The issue is I want a toolbar. This is a two part question:


  1. 可以向 QDialog ? (也可以在Qt Designer中执行此操作)

  2. 如果1.不可能,我如何使 QMainWindow modal?

  1. Is it possible to add a toolbar to a QDialog? (also is it possible to do this in Qt Designer?)
  2. If 1. is not possible, how can I make a QMainWindow modal?


推荐答案


  1. > 可以直接在 QDialog 中添加 QToolBar QDialog 只继承 QWidget 而不是 QMainWindow ,因为没有方法 addToolBar()

  1. It is not directly possible to add a QToolBar to a QDialog in the sense that QDialog inherits only QWidget and not QMainWindow, as you noted (hence do not have the method addToolBar())

您不能创建 QMainWindow modal,但您可以在 QDialog 中插入 QMainWindow

You can't make a QMainWindow modal, but you can insert a QMainWindow in a QDialog this way:

代码:

MyDialog::MyDialog() :
    QDialog()
{
    QMainWindow * mainWindow = new QMainWindow(); // or your own class
                                                  // inheriting QMainWindow

    QToolBar * myToolBar = new QToolBar();
    mainWindow->addToolBar(myToolBar);

    QHBoxLayout * layout = new QHBoxLayout();
    layout->addWidget(mainWindow);
    setLayout(layout);
}

确实, QMainWindow 不一定必须是顶级窗口部件,你甚至可以插入几个 QMainWindow 作为单个窗口小部件的孩子(可能不是最聪明的选择,因为用户可能会与菜单栏,工具栏,停靠窗口小部件等的单独集合混淆)。

Indeed, a QMainWindow doesn't necessarily have to be a top-level widget, and you can even insert several QMainWindows as children of a single widget (may not be the wisest choice though, as the user would probably be confused with the separate sets of menu bars, toolbars, dock widgets, etc.).

这篇关于你能添加一个工具栏到QDialog吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆