How to set font, size and color for the Text of QPushButton in Qt5.6.1 using QPalette? As I am curious to know how we can set these properties without using QStyleSheet in Qt. Also how we can set hex code of color in QT. Please suggest any way to do with QPalette. Thanks
How to customize text on Qpushbutton using QPalette?
7.1k Views Asked by Avi At
2
There are 2 best solutions below
0
Avi
On
I agree with the above mentioned points.
Following is the another approach to achieve the Font Customization with QWidgets.
QPushButton *button3 = new QPushButton("CheckFont", this);
button3->setGeometry(QRect(QPoint(50,50),QSize(200,50)));
QFont FontObj;
FontObj.setFamily(QStringLiteral("Helvetica [Cronyx]"));
FontObj.setPointSize(15);
FontObj.setBold(true);
FontObj.setUnderline(true);
button3->setFont(FontObj);
Also when Color code is in format like "#ffffff" (which is white color code) then you can use following way to set the hex color code with QPalette.
pal.setColor(QPalette::Button, QColor(QRgb("#ffffff")));
OR
pal.setColor(QPalette::Button, QColor("#ffffff"));
Related Questions in QT
- C++ template using pointer and non pointer arguments in a QVector
- Using QPointer and QObject::connect with C++11
- qt How to style a QToolBar > QToolButton overflow button?
- Qt - Repeatedly write at beginning of file
- C++ Mongodb driver, not working
- deletion and cleanup of worker thread in Qt crashes
- How to drap item from QTableView to QPushButton?
- get image type from qimage
- C++ QT Getting part from QString
- How to connect a destroyed signal of C++ object from QML?
- How to get shader version from QOpenGLShader?
- Size of Qt QRadioButton able to get smaller, but not larger than default
- error WinSock.h has already been included Boost Windows Qt
- How to call a non-class member function with pointers as parameters with QtConcurrent::run?
- What is the difference between MinGW SEH and MinGW SJLJ?
Related Questions in QTGUI
- C++ QT Getting part from QString
- How to highlight text in the title?
- How can I use replacedlg.ui in mainwindow.cpp?
- some parts of Qrect missing
- How to use automatically added Qt-elements
- How to set QInputDialog as modal
- QColor hsl hue precision
- How to close the qt widget ui on a button clicked in promoted widget?
- PyQt Window Focus on right-click
- Accessing QT GUI from CALLBACK
- New Line Character and PyQt
- QScrollbar scroll to center
- How to get the text from QTableWidget::setCellWidget()
- QTabWidget tab not showing up
- "QComboBox Pop-up" expanding and QtWebkit
Related Questions in QPUSHBUTTON
- How to connect Qt combobox with pushbutton and some kind of widget that shows picture?
- Check the state of QPushButton in PyQt4?
- Can we connect QPushButton to change values of QSlider?
- Two colours text in QPushButton
- QT - connecting wrong button from member QWidget
- How can we delete icon from QPushButton?
- PySide: base on the groupbox example of PySide-Example , issue An error native Qt signal is not callable
- PySide : How to get the clicked QPushButton object in the QPushButton clicked slot?
- How to insert QPushButton into a QLabel (PyQt4)?
- Simplest way to click a button with QTest
- QBoxLayout add QTextEdit full size and QPushButton
- Change icon on state change using Qt stylesheet
- Running WampServer using a QPushButton
- sending a parameter by button press with QPushButton
- Connect Arduino digital pin to input pin and work as button
Related Questions in QCOLOR
- Fill function in basic graphics app in Qt
- char[4] to QColor Conversion
- QColor into list for later retrieval
- Why does QColor use 32-bit signed int to represent e.g. rgba values?
- How to display a QColor from QColorDialog in a widget?
- Converting QColor into QString without losing alpha value
- Cant set the background color of a QTableWidgetItem?
- Set a button of custom color to a disabled style
- How to convert between QT-QColor with opencv-cv::Scalar?
- How do I set custom colours on a pyqt QColorDialog?
- How to change saturation and value using slider qcolor?
- QTableWidgetItem editor background color
- Qt- How to get the color of a QPoint in QImage for QPixmap
- Is it possible to store QColor in a QMap as key
- Qt5 error: ‘ColorKeyMap’ does not name a type
Related Questions in QPALETTE
- Change disabled QIcon tint color
- Overriding Qt Stylesheet in QStyledItemDelegate
- How can I access Qt's used border color for use in qtstylesheets widget styling (via QPalette)?
- QPalette and app.setStyleSheet() not impacting child Widget colors
- PyQt6 - QPalette not working correctly with mdiArea windows
- How Can I Prevent Qt Designer from Applying QPalette to QComboBox - Python
- How to set QPalette back to default system palette?
- Qt use palette color in stylesheet
- How to get QWidget background-color after set a QStyleSheet
- How to change the QCombobox highlight colour in PyQt
- Distinguish alternating rows color from selection color in QTableWidget
- How to color a PyQt QTabwidget
- How to change current color group for QPalette
- How can I change color of checkBox in qt with using python?
- How to use QPROPERTY in QPalette?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
A
QPalettecontains color groups for each widget state. It does not contain font/size information.You can use
QWidget::setPalette()to change specific color roles (Button, ButtonText, Window. . .), and useQWidget::setFont()to change font family/size. For example:In order for palettes to work properly, you may want to first use Fusion style in the application by calling:
before instantiating the
QApplicationinstance inmain()because some styles do not use the palette for all drawing, for instance, if they make use of native theme engines. This is the case for both the Windows XP, Windows Vista, and the OS X styles.Also, You may want to set the palette/font on the whole application, so that you get those colors in all widgets in the application. Something like this: