Reputation: 871
This is the standard Color Dialog
box from Qt5
Is it possible to view the basic colors alone and remove the color gradient from the dialog?
Upvotes: 0
Views: 913
Reputation: 18514
I found simple solution of this problem. It is not a removing, but with my code, we cannot see this gradient and cannot use it.
We need create subclass. Let's code:
mycolordialog.h
#ifndef MYCOLORDIALOG_H
#define MYCOLORDIALOG_H
#include <QColorDialog>
#include <QLabel>
class MyColorDialog : public QColorDialog
{
Q_OBJECT
public:
explicit MyColorDialog(QWidget *parent = 0);
signals:
public slots:
};
#endif // MYCOLORDIALOG_H
mycolordialog.cpp
#include "mycolordialog.h"
MyColorDialog::MyColorDialog(QWidget *parent) :
QColorDialog(parent)
{
QLabel * l = new QLabel("Teeeeext",this);
l->setGeometry(245,5,325,215);//this values control the area and position of label
//you can change this values and remove another area of main dialog window
QPixmap pixmap("G:/2/qt.jpg");
l->setPixmap(pixmap.scaled(325,215,Qt::IgnoreAspectRatio));;//resize our picture
l->show();
}
How to use it???
#include "mycolordialog.h"
//...
void MainWindow::on_pushButton_16_clicked()
{
MyColorDialog cd;
cd.exec();
qDebug() << cd.selectedColor();
}
You can set in label beautiful logo of your app, or something another. I use logo from here http://reichertbrothers.com/images/qt-logo.png , but I convert it into jpg format.
What we get???
Notice, that all another area is available and you can choose any color and work as you want, but this gradient window is remove!!
I hope it helps.
Upvotes: 1
Reputation: 132
The options that you can select to modify the look of the color dialog are in the QColorDialog documentation.
enum ColorDialogOption {
ShowAlphaChannel = 0x00000001,
NoButtons = 0x00000002,
DontUseNativeDialog = 0x00000004
};
This options do not hide the color picker, therefore you will have to implement your custom color picker.
Upvotes: 0