Changing QLineEdit Text Color

Summary : This code shows how to change QLineEdit text color.
 Qt Version:  4.7.4
Date Added: 2011-07-02

If QT GUI styling such as background or foreground coloring does not work as expected , check your qtconfig settings!
#include <QApplication>
#include <QMainWindow>
#include <QLineEdit>
#include <QHBoxLayout>

int main(int argc, char **argv)
{
	QApplication app(argc, argv);

	QMainWindow *window = new QMainWindow();    
    
        window->setWindowTitle(QString::fromUtf8("QLineEdit Text Color"));
        window->resize(336, 227);
	
        QWidget *centralWidget = new QWidget(window);
	QHBoxLayout *layout = new QHBoxLayout();
	
	centralWidget->setLayout(layout);	
	QLineEdit *lineEdit = new QLineEdit(centralWidget);

	//Create QPalette here and set its Color and Color Role
	QPalette *palette = new QPalette();
	palette->setColor(QPalette::Text,Qt::red);
	lineEdit->setPalette(*palette);
	
	//Add to horizontal layout to center qLineEdit
	layout->addWidget(lineEdit);		
	lineEdit->setFixedSize(300, 20);
	
	window->setCentralWidget(centralWidget);

	window->show();
	return app.exec();
}
Output :
QLineEdit Text Color


Similar Examples
QLineEdit Password Input Style Example
Changing QLineEdit Background Color
QLineEdit TextChanged Example
Changing QLineEdit Text Highlight Background Color
Centering Text of QLineEdit
Disabled QLineEdit Example
Set QLineEdit Letter Spacing
QLineEdit Set Custom Font Example
Set Background Image with Custom Font

Examples About Some Qt Classes
QLcdNumberQTimer
QPushButtonQMessageBox
QTabWidgetQtConcurrent
QLabelQList
QKeyEventQSlider
QFontDialogQSpinBox
QTableWidgetQTextBrowser
Qt StylesheetsQCheckBox
QComboBoxQCloseEvent
QProgressBarQProgressDialog
QTreeWidgetQSignalMapper



Recommend This : Bookmark and Share
 
Want any example ? Feel free to tell us:
(Max. 2000 characters)
Please note that we do not guarantee to respond.Thanks.

C++
OpenSceneGraph
Fundamentals
QT
Boost
wxWidgets
Java
Python



Copyright 2011 - 2013 | All Rights Reserved
All trademarks are properties of their respective owners.
Contact| Privacy Policy| About Us