Reputation: 47
im trying to change the font size of a QTextEdit by using a QComboBox which is filled in with different values, so for example when I choose a value in the QComboBox it will change the QTextEdits size to the value I have selected. I have values in the QComboBox but I don't know how to change the QTextEdit's value to the value I have selected.
Below is the code I used to fill the QComboBox with values:
for (int i = 0; i < 102; i+=2){
QStringList list = (QStringList()<<QString::number(i));
ui->combobox->addItem(list);
Any help on what to do from here would be appreciated thank you!
Upvotes: 0
Views: 1546
Reputation: 1974
QTextEdit* textEdit = new QTextEdit(......);
QComboBox* fontSizeCombo = new QComboBox(....);
for (int i = 1; i < 102; i += 2) {
fontSizeCombo->addItem(QString::number(i));
}
connect(fontSizeCombo, SIGNAL(currentIndexChanged(QString), SLOT(changeFontSize(QString));
void MyClass::changeFontSize(const QString& selected)
{
textEdit->setFontPointSize(selected.toInt());
}
Don't need appending QStringList
with each item.
Don't set font size to 0. Excerpt from the Qt docs:
Note that if s is zero or negative, the behavior of this function is not defined.
Upvotes: 1