Diff between QBrush and QPen
hi friends,
i try to send the QPen value as argument like
in lineitem.h
Code:
{
Q_OBJECT
public:
private:
int xvalue, yvalue;
}
in lineitem.cpp
Code:
LineItem
::LineItem(const QLineF &line,
const QPen &pen
) pen(pen)
{
{
painter->setPen(pen);
painter->drawLine(line());
}
in graphicsview
Code:
line1
= new LineItem
(QLineF(2,
4,
2 ,
30), Qt
::green);
line1->setPos(100,550);
scene->addItem(line1);
its giving error as
dualmon.cpp:93: error: no matching function for call to ‘LineItem::LineItem(QLineF, Qt::GlobalColor)’
lineitem.h:13: note: candidates are: LineItem::LineItem(const QLineF&, const QPen&)
lineitem.h:8: note: LineItem::LineItem(const LineItem&)
or as
but if the same QPen i replace with QBrush its running perfectly ...
i can send color as argument for QBrush but not for QPen why?
please help :)
}
Re: Diff between QBrush and QPen
the color u gave is a Qt::GlobalColor , when u use QBrush instead of QPen, the following constructor is used(since the second argument is default and first is already given)
QBrush ( Qt::GlobalColor color, Qt::BrushStyle style = Qt::SolidPattern )
for QPen, there is no such constructor :)
Re: Diff between QBrush and QPen
thanks .. so i have to send QColor instead of QPen ...
Re: Diff between QBrush and QPen
Quote:
Originally Posted by
wagmare
thanks .. so i have to send QColor instead of QPen ...
:confused::confused::confused: If you want to sent a QColor why you define a constructor expecting a QPen? What's about defining:
Code:
...
LineItem
(const QLineF &rect,
const Qt
::GlobalColor color
);
with for example:
Code:
LineItem
(const QLineF &rect,
const Qt
::GlobalColor color
){
}
then you will be save.
Re: Diff between QBrush and QPen
no just i am telling i cant send GlobalColor to QPen .. just send the color value to the constructor .. from the value i will set it to QPen
Re: Diff between QBrush and QPen
Well, you can set up a QPen from a GlobalColor. The only thing is that Qt does this not for you. So just do it by yourself by transforming the GlobalColor to a QColor and set this to the QPen.