Hi,
I am trying to embed QColorDialog in a QWidget. After I add the QColorDialog, it shows up correctly, but the layouting doesn't work correctly.
When I stretch the QWidget by dragging from the bottom right corner, the QColorDialog doesn't occupy the entire resized QWidget. It only stays in the center.
The minimal code to reproduce this is as follows:
#include <QApplication>
#include <QWidget>
#include <QColorDialog>
#include <QHBoxLayout>
int main(int argc, char *argv[])
{
cDialog->setWindowFlags(Qt::Widget);
hl->addWidget(cDialog);
w->setLayout(hl);
w->show();
return a.exec();
}
#include <QApplication>
#include <QWidget>
#include <QColorDialog>
#include <QHBoxLayout>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget *w = new QWidget(nullptr);
QColorDialog *cDialog = new QColorDialog(w);
cDialog->setWindowFlags(Qt::Widget);
cDialog->setOptions(QColorDialog::DontUseNativeDialog
| QColorDialog::NoButtons);
QHBoxLayout *hl = new QHBoxLayout(w);
hl->addWidget(cDialog);
w->setLayout(hl);
w->show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
If I replace the QColorDialog with QFontDialog, this works correctly. Please see the attached screenshot that shows the issue
Capture-QColorDialog_in_QWidget.jpg
Can anyone help me fix the issue?
Thanks,
Ashish
Bookmarks