Hi everyone,
i want to make a program with a text field and two check boxes: bold and italics which adjust the font in the text field accordingly.
I made QFont a private member in Stuff.h and initialized it in Stuff.cpp - but there seems to be some problem there. I followed the documentation so i dont understand why theres a problem.
the code and errors are mentioned below
Stuff.h
#ifndef STUFF_H
#define STUFF_H
#include <QWidget>
#include <QFont>
namespace Ui {
class Stuff;
}
{
Q_OBJECT
public:
explicit Stuff
(QWidget *parent
= 0);
~Stuff();
private slots:
void adjustFont();
private:
Ui::Stuff *ui;
QFont *font;
// font declared here! };
#endif
#ifndef STUFF_H
#define STUFF_H
#include <QWidget>
#include <QFont>
namespace Ui {
class Stuff;
}
class Stuff : public QWidget
{
Q_OBJECT
public:
explicit Stuff(QWidget *parent = 0);
~Stuff();
private slots:
void adjustFont();
private:
Ui::Stuff *ui;
QFont *font;// font declared here!
};
#endif
To copy to clipboard, switch view to plain text mode
#include "stuff.h"
#include "ui_stuff.h"
#include <QButtonGroup>
#include <QFont>
ui(new Ui::Stuff)
{
ui->setupUi(this);
font
= new QFont("Times",
12);
group->addButton(ui->SBoldButton);
group->addButton(ui->SItalicButton);
group->setExclusive(false);
ui->SLineEdit->setText("this is a line");
ui->SLineEdit->setFont(font);// /home/ubuntu/QtProjects/Stuff-build-desktop/../Stuff/stuff.cpp:23: error: no matching function for call to ‘QLineEdit::setFont(QFont*&)’
connect(group,SIGNAL(buttonClicked(int)),this,SLOT(adjustFont()));
connect(ui->SQuitButton,SIGNAL(clicked()),qApp,SLOT(quit()));
}
Stuff::~Stuff()
{
delete ui;
}
void Stuff::adjustFont()
{
Qt::CheckState boldState;
Qt::CheckState italicState;
boldState=ui->SBoldButton->checkState();
italicState=ui->SBoldButton->checkState();
if(boldState==Qt::Checked && italicState!=Qt::Checked)
{
ui->SLineEdit->setFont(font->setBold(true));///home/ubuntu/QtProjects/Stuff-build-desktop/../Stuff/stuff.cpp:44: error: invalid use of void expression
ui->SLineEdit->setFont(font->setItalic(false));//same as above and applies for all similar lines of code below
}
else if(boldState!=Qt::Checked && italicState==Qt::Checked)
{
ui->SLineEdit->setFont(font->setBold(false));
ui->SLineEdit->setFont(font->setItalic(true));
}
else if(boldState==Qt::Checked && italicState==Qt::Checked)
{
ui->SLineEdit->setFont(font->setBold(true));
ui->SLineEdit->setFont(font->setItalic(true));
}
else
{
ui->SLineEdit->setFont(font->setBold(false));
ui->SLineEdit->setFont(font->setItalic(false));
}
}
#include "stuff.h"
#include "ui_stuff.h"
#include <QButtonGroup>
#include <QFont>
Stuff::Stuff(QWidget *parent) :
QWidget(parent),
ui(new Ui::Stuff)
{
ui->setupUi(this);
font = new QFont("Times",12);
QButtonGroup *group = new QButtonGroup(this);
group->addButton(ui->SBoldButton);
group->addButton(ui->SItalicButton);
group->setExclusive(false);
ui->SLineEdit->setText("this is a line");
ui->SLineEdit->setFont(font);// /home/ubuntu/QtProjects/Stuff-build-desktop/../Stuff/stuff.cpp:23: error: no matching function for call to ‘QLineEdit::setFont(QFont*&)’
connect(group,SIGNAL(buttonClicked(int)),this,SLOT(adjustFont()));
connect(ui->SQuitButton,SIGNAL(clicked()),qApp,SLOT(quit()));
}
Stuff::~Stuff()
{
delete ui;
}
void Stuff::adjustFont()
{
Qt::CheckState boldState;
Qt::CheckState italicState;
boldState=ui->SBoldButton->checkState();
italicState=ui->SBoldButton->checkState();
if(boldState==Qt::Checked && italicState!=Qt::Checked)
{
ui->SLineEdit->setFont(font->setBold(true));///home/ubuntu/QtProjects/Stuff-build-desktop/../Stuff/stuff.cpp:44: error: invalid use of void expression
ui->SLineEdit->setFont(font->setItalic(false));//same as above and applies for all similar lines of code below
}
else if(boldState!=Qt::Checked && italicState==Qt::Checked)
{
ui->SLineEdit->setFont(font->setBold(false));
ui->SLineEdit->setFont(font->setItalic(true));
}
else if(boldState==Qt::Checked && italicState==Qt::Checked)
{
ui->SLineEdit->setFont(font->setBold(true));
ui->SLineEdit->setFont(font->setItalic(true));
}
else
{
ui->SLineEdit->setFont(font->setBold(false));
ui->SLineEdit->setFont(font->setItalic(false));
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks