2009-05-20 34 views

回答

0

如果有办法做到这一点干净,我不知道它。在我看来,你有两个选择:

  • 继承它,复制,实际上构造窗口小部件,进行编辑,以去除创建对话框窗口中的一部分,并与其他一些容器取代它的代码。
  • 如果您在使用该特定对话框时没有完成设置,则qt解决方案中的颜色三角形小部件可能会起作用,因为它不是对话框窗口。您可以在http找到它:// doc.trolltech.com/solutions/4/qtcolortriangle/qtcolortriangle.html(删除链接的空间)
+0

这是可能的。请参阅下面的@ Wiz解决方案。 – metal 2013-10-22 15:20:51

2

你可能想看看一些Qt的解决方案,这将做你想做的至少一部分。例如,请参阅Color Picker解决方案,他们注意到该解决方案现在也可以作为LGPL许可的库。我记得Qt实验室的一些关于将Qt小部件嵌入到QGraphicsScene中的工作,包括QDialog s。您可能会这样做,然后更改图形场景中的视图,以便只有用户感兴趣的颜色选择器对话框的一部分对用户可见。但是,这听起来很骇人听闻。

+0

此解决方案不再有效。是否有更新的产品链接? – metal 2013-10-23 12:22:35

0

使用QGraphicsView,并添加QDialog它。如果你想显示对话框,并将QGraphicsView添加到小部件。

2

您可以通过设置正确的窗口标志以非常简单的方式将其清理干净。

QColorDialog8 colorDialog = new .... 
colorDialog->setWindowFlags(Qt::SubWindow); 
15

QColorDialog是一个对话框,意味着它是一个小部件。您只需设置几个窗口标志并将其放入您的布局中即可。这里有一个(测试)例如:

#include <QApplication> 
#include <QMainWindow> 
#include <QColorDialog> 

int main(int argc, char *argv[]) 
{ 
    QApplication a(argc, argv); 

    /* setup a quick and dirty window */ 
    QMainWindow app; 
    app.setGeometry(250, 250, 600, 400); 

    QColorDialog *colorDialog = new QColorDialog(&app); 
    /* set it as our widiget, you can add it to a layout or something */ 
    app.setCentralWidget(colorDialog); 
    /* define it as a Qt::Widget (SubWindow would also work) instead of a dialog */ 
    colorDialog->setWindowFlags(Qt::Widget); 
    /* a few options that we must set for it to work nicely */ 
    colorDialog->setOptions(
       /* do not use native dialog */ 
       QColorDialog::DontUseNativeDialog 
       /* you don't need to set it, but if you don't set this 
        the "OK" and "Cancel" buttons will show up, I don't 
        think you'd want that. */ 
       | QColorDialog::NoButtons 
    ); 

    app.show(); 
    return a.exec(); 
} 
+1

工作就像一个魅力对我来说。有关使其在菜单中工作的更多提示,请参阅下面的答案。 – metal 2013-10-22 17:13:12

0

大厦@奇才的答案,我做了我的弹出式菜单关闭使用一些C++ 11功能(lambda表达式和经销商的工具栏按钮;用VS2010和gcc 4.6工程使用Qt 5.1.1):

auto dialog = new QColorDialog(); 
dialog->setWindowFlags(Qt::Widget); 
dialog->setOptions(QColorDialog::DontUseNativeDialog | QColorDialog::ShowAlphaChannel); 

auto action = new QWidgetAction(0); 
action->setDefaultWidget(dialog); 

auto menu = new QMenu(); 
menu->addAction(action); 

// The dialog-as-widget closes on Ok/cancel, but the menu that holds it 
// doesn't. We connect the two here. Because the dialog hides itself, 
// we need to reshow it when the menu is coming up again. 
connect(menu, &QMenu::aboutToShow,  [=] { dialog->show(); }); 
connect(dialog, &QColorDialog::rejected, [=] { menu->hide(); }); 
connect(dialog, &QColorDialog::colorSelected, 
    [=](const QColor& color) 
    { 
     menu->hide(); 
     OnFillColorChanged(color); // Call the "slot" in this class 
    }); 

auto button = new QToolButton(); 
button->setIcon(QIcon(":/images/whatev.png")); 
button->setText(tr("Fill")); 
button->setStatusTip(tr("Choose fill color")); 
button->setMenu(menu); 
button->setPopupMode(QToolButton::InstantPopup); 
button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); 

toolbar->addWidget(button); // toolbar is defined elsewhere 
+0

只需注意您的修改后的代码不再是Qt4,因为此问题带有标记。 – Wiz 2013-10-22 21:35:18

0

此基础上从“金属”前面的回答我建议你在派生类中的QAction的创建方法如下:

void MyQAction::setPopupDialog(QDialog* dialog) { 

    QWidgetAction* action = new QWidgetAction(NULL); 
    action->setDefaultWidget(dialog); 

    QMenu* menu = new QMenu(); 
    menu->addAction(action); 
    // Fix issues related to the way the dialogbox hide/show. Restablish proper handling, 
    // based on our requirement. 
    connect(menu, SIGNAL(aboutToShow()), dialog, SLOT(show())); 
    connect(dialog, SIGNAL(finished(int)), menu, SLOT(hide())); 

    setMenu(menu); 
} 

这会为这个过程自动化任何对话框。

相关问题