bal*_*los 8 user-interface qt qt4 color-picker
我想使用QColorDialog不是一个对话窗口,而是作为一个小部件,我可以插入到布局中.(更具体地说,作为上下文菜单中的自定义子菜单)
我查看了QColorDialog源代码,我可能会复制QColorDialog的一部分内部实现来实现这一目标,但是有更简洁的方法吗?我正在使用Qt 4.5.1 ...
Wiz*_*Wiz 17
QColorDialog是一个对话框,意味着IT是一个小部件.您需要做的就是设置一些窗口标志,并根据需要将其放入您的布局中.这是一个(测试的)示例:
#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();
}
Len*_*ick -1
如果有一种方法可以干净地做到这一点,我不知道。在我看来,你有几个选择: