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
- qt c++ fonction converting adress to coordinates (longitude, latitude)
- Qml table and chart using python
- Qt: running callback in the main thread from the worker thread
- i have installed qt version 6.0.3 and this error QMYSQL driver not loaded displaying again and again
- Frameless Qt + WinAPI maximized window size is bigger than the availableGeometry()
- new window with c++ qt
- How to get scaling from transformation matrix
- How to build just Qt core libraries from Qt sources
- doxyqml not documenting qml files properly
- Incorrect assignment from a QStringList to a char * array
- How to make QT Chart size larger than widget size?
- Queued async operations with QtConcurrent interfere QImage from freed
- Questions about qt5 dynamic link library
- how to document QML files inside C++ project?
- How do I keep my screen contents centered and also have a scrollbar in QT?
Related Questions in QTGUI
- GNUradio QT GUI Time Sink plot colour and line widths configuration
- Maya UI for browsing assets failing to propagate multiple lists?
- QTransform Include conflict between QtGui and Qt3D
- How can I rotate an ellipse in a QPainterPath in Qt?
- Am I correctly importing the pyqt module library? Execution returns error "module called qdialog is not found"
- AttributeError: module 'pyqtgraph.Qt.QtGui' has no attribute 'QApplication'."
- Windows property "SIZE ON DISK" How to get this size by qt C++
- PyQtgraph - Plotting real-time data - Add "line labels" next to graph which move up and down in concert with real-time data (see illustration in post)
- Qt GUI: How can I make the legends that appear when I plot in a widget not appear?
- RuntimeError while ploting data from loop using pygtgr
- How do I write an ip address on Qlineedit regularly QT with mask
- Qt Custom CheckBox, help about PaintEvent
- QVTKWidget is transparent
- PyQt5 grabWindow captures black screen instead of the selected area
- toolbarBreak disappears when deleting QToolBar
Related Questions in QPUSHBUTTON
- Problem with QPushButton icons appearing PySide6
- Many QPushButtons clicked connecting using exec()
- QPushButton background color always looks the same in Qt6 regardless of alpha value
- PushButton Color Change By Mouse move
- PyQt/Pyside: storing individual value in QPushButtons(or QWidgets in general)
- PyQt - PushButton Hide and Show works not as excepted
- PyQt5 - Unable to get QPushButton to size properly in a QGridLayout
- Sometimes (but not always) This custom info button doesn't display itself in full. Any ideas why?
- Implementing Qpushbutton in Qt and cpp
- PYQT6 multiple Buttons Layout
- Why is clicking a QPushButton causing the program to crash?
- Pyside 6.5.1 widget created in for-loop has wrong attributes
- Why is my PyQt6 QPushButton not clicking in my QTableWidget and QWidget on my MainWindow?
- How to get the text of dynamically added QPushButton when clicked
- pyqt5 enterEvent - self.sender() returns NoneType
Related Questions in QCOLOR
- Convert RGB QColor to HSL
- Why does QColor use 32-bit signed int to represent e.g. rgba values?
- QColor to human readable string
- How to change saturation and value using slider qcolor?
- Qt5 error: ‘ColorKeyMap’ does not name a type
- How to get QColor::greenF color value exactly between 0 and 1 instead of rounding off?
- Converting QColor into QString without losing alpha value
- Qt- How to get the color of a QPoint in QImage for QPixmap
- Pyside - QcolorDialog signals
- Cant set the background color of a QTableWidgetItem?
- QColor into list for later retrieval
- QColor Hot to get darker image (array of pixels) in qt creator (using function darker)?
- Compare the color of two QColor objects
- QPalette Does not work in QTabBar?
- how to change the intensity of curve colour in Qcustomplot with respect to x-axis?
Related Questions in QPALETTE
- How to stylize custom Qt widgets globally?
- Selection color for QTableWidget cell is different if custom cellwidget is used
- QPalette has no attribute PlaceholderText?
- QPalette and app.setStyleSheet() not impacting child Widget colors
- How Can I Prevent Qt Designer from Applying QPalette to QComboBox - Python
- QPalette does not change the background of the button
- QPalette not changing correctly in Qt6. Changes only visible when window is inactive
- QPalette propagation to QDialog not working
- PyQt6 - QPalette not working correctly with mdiArea windows
- How can I access Qt's used border color for use in qtstylesheets widget styling (via QPalette)?
- Change palette of PyQt5
- Updating the default color of anchors in a QTextDocument
- Mimic QApplication::palette() based color style behavior
- Overriding Qt Stylesheet in QStyledItemDelegate
- Qt use palette color in stylesheet
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 # Hahtags
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: