Qt Color Picker Widget?

I have a subclass of QDialog that provides the user with some options for choosing them. One of these options is color. I saw QColorDialog , and I need something much simpler, it is also a normal widget, so I can add part of my dialog to my layout. Does Qt offer anything like this, or should I make my own? If the latter, which one is the best strategy?

+7
source share
4 answers

Have you looked at QtColorPicker, part of Qt Solutions?

QtColorPicker

QtColorPicker provides a small widget in the form of a QComboBox with a customizable set of predefined colors for easy and quick access. Pressing the button ... will open QColorDialog . It is licensed under the LGPL, so with dynamic linking and proper attribution it can be used in commercial software. Find QtColorPicker and you will find it. Here is a link to one site that hosts many of the Qt Solutions components:

https://github.com/pothosware/PothosFlow/tree/master/qtcolorpicker

+8
source

Qt doesnโ€™t offer anything easier than QColorDialog initially, but there are several color picker widgets as part of wwWidgets , the user made a set of widgets for Qt (note that this is โ€œwwWidgetsโ€ with โ€œwโ€, not โ€œwxWidgetsโ€ with โ€œxโ€) .

+4
source

There is a very simple way to implement using QPushButton to display the current color and pickup when pressed:

Definition:

 #include <QPushButton> #include <QColor> class SelectColorButton : public QPushButton { Q_OBJECT public: SelectColorButton( QWidget* parent ); void setColor( const QColor& color ); const QColor& getColor(); public slots: void updateColor(); void changeColor(); private: QColor color; }; 

Implementation:

 #include <QColorDialog> SelectColorButton::SelectColorButton( QWidget* parent ) { connect( this, SIGNAL(clicked()), this, SLOT(changeColor()) ); } void SelectColorButton::updateColor() { setStyleSheet( "background-color: " + color.name() ); } void SelectColorButton::changeColor() { QColor newColor = QColorDialog::getColor(color,parentWidget()); if ( newColor != color ) { setColor( newColor ); } } void SelectColorButton::setColor( const QColor& color ) { this->color = color; updateColor(); } const QColor& SelectColorButton::getColor() { return color; } 
+3
source

I think QColorDialog is best for your application. If you want to go for something simpler, it will work with reduced functionality. I donโ€™t know which standard widget in Qt offers this option, but you can try the following:

  • QCombobox with each entry matching a different color. Perhaps you can even have the colors of the names in their actual color.

  • One or more sliders to adjust the hue, saturation, val or R, G, B components.

  • QLineEdit fields for individual components R, G, B. You can also have a signal / slot mechanism in which, when the user changes color, the color displayed to the user changes accordingly.

  • You may have โ€œ+โ€ and โ€œ-โ€ signs to increase / decrease the specified values โ€‹โ€‹of color components.

I hope the above gives you some ideas.

+2
source

Source: https://habr.com/ru/post/1497278/


All Articles