[Solved] Set Font of QTextEdit and QListWidget
-
I am running a linux OS. The courier font in the text editor is also courier, but does not appear to be fixed width. I've also tried:
@QListWidgetItem * tmpItem = new QListWidgetItem(temp, lwLogList);
QFont font = QFont ("Courier");
font.setStyleHint (QFont::Monospace);
font.setPointSize (8);
font.setFixedPitch (true);
tmpItem->setFont (font);@But this doesn't seem to change anything, other than some of the parameters when the font type is printed out.
QFont( "Courier,8,-1,2,50,0,0,0,1,0" ) - from the above code
vs.
QFont( "Courier,8,-1,5,50,0,0,0,0,0" ) - from setting the style sheet. -
Here is the code for the dialog. It has a text box and underneath is a button bar.
@setWindowTitle ("Title");
QVBoxLayout *mainLayout = new QVBoxLayout;textEdit = new QTextEdit (this);
QFont font = QFont ("Courier");
font.setStyleHint (QFont::Monospace);
font.setPointSize (8);
font.setFixedPitch (true);
textEdit->setFont (font);mainLayout->addWidget (textEdit);
setAutoFillBackground(true);QHBoxLayout *bar = new QHBoxLayout;
btnBack = new QPushButton ("Back", this);
btnBack->setMinimumSize (QSize (80, 40));
bar->addWidget (btnBack);
btnSave = new QPushButton ("Save", this);
btnSave->setMinimumSize (QSize (80, 40));
bar->addWidget (btnSave);
btnPrint = new QPushButton ("Print", this);
btnPrint->setMinimumSize (QSize (80, 40));
bar->addWidget (btnPrint);
btnErase = new QPushButton ("Erase", this);
btnErase->setMinimumSize (QSize (80, 40));
bar->addWidget (btnErase);
bar->addStretch ();mainLayout->addLayout (bar);
mainLayout->setContentsMargins (6, 6, 6, 6);
setLayout (mainLayout);
@Thanks for your help,
Katelyn -
Oops - sorry about that. Here is an updated version:
@setWindowTitle ("Title");
QVBoxLayout *mainLayout = new QVBoxLayout;lwListWidget = new QListWidget (this);
QFont font = QFont ("Courier");
font.setStyleHint (QFont::Monospace);
font.setPointSize (8);
font.setFixedPitch (true);
lwListWidget->setFont (font);mainLayout->addWidget (lwListWidget);
setAutoFillBackground(true);QHBoxLayout *bar = new QHBoxLayout;
btnBack = new QPushButton ("Back", this);
btnBack->setMinimumSize (QSize (80, 40));
bar->addWidget (btnBack);
btnSave = new QPushButton ("Save", this);
btnSave->setMinimumSize (QSize (80, 40));
bar->addWidget (btnSave);
btnPrint = new QPushButton ("Print", this);
btnPrint->setMinimumSize (QSize (80, 40));
bar->addWidget (btnPrint);
btnErase = new QPushButton ("Erase", this);
btnErase->setMinimumSize (QSize (80, 40));
bar->addWidget (btnErase);
bar->addStretch ();mainLayout->addLayout (bar);
mainLayout->setContentsMargins (6, 6, 6, 6);
setLayout (mainLayout);@Then I add items with the following code:
@QListWidgetItem * tmpItem = new QListWidgetItem(temp, lwListWidget); // where temp is a QString
QFont font = QFont ("Courier");
font.setStyleHint (QFont::Monospace);
font.setPointSize (8);
font.setFixedPitch (true);
tmpItem->setFont (font);@I cannot add the items directly in Qt Designer or in the constructor because I won't know what they are at that time.
Thanks,
Katelyn -
Within the QListWidget I have a list of items. These items display a name, date and a status.
For example:
JobA June 26, 2011 Completed
JobB July 4, 2011 In ProgressNames, dates and statuses are different lengths, but I would like each column to match up. I am trying a QTableView and only allowing complete rows to be selected. Does this seem like an acceptable solution?
-
i tried like this. it is working for english fonts. but it is not working for tamil fonts.
@ui->label1->setStyleSheet ("font: 40pt "Lohit Tamil";");
ui->label1->setText("சென்னை");
//ui->label1->setText("tamil");
ui->label1->show();@[quote author="Eddy" date="1311141291"]You can find the explanation for that behaviour in the "QWidget docs :":http://doc.qt.nokia.com/4.7/qwidget.html#font-prop
You can solve this by giving your whole dialog the font you want in it's constructor :
@setFont (QFont ("Courier", 9)); @
But I don't know if that's ok with your initial design.The easiest way to solve this is to use stylesheets which take precedence over setFont.
@ui->textEdit->setStyleSheet("font: 9pt "Courier";");@
(You can experiment with this using Qt Designer : RMB on a widget > Change Stylesheet.)But using stylesheets per widget doesn't use it's real force. You can set this for the whole of your application to get a look and feel which is the same everywhere.
[/quote] -
Hi Sasireka,
Do you have tamil font installed in your computer?
-
"This question has been solved here: ":http://qt-project.org/forums/viewthread/47761/