Results 1 to 6 of 6

Thread: Diff between QBrush and QPen

  1. #1
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    658
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Diff between QBrush and QPen

    hi friends,
    i try to send the QPen value as argument like
    in lineitem.h
    Qt Code:
    1. class LineItem : public QObject, public QGraphicsLineItem
    2. {
    3. Q_OBJECT
    4. public:
    5. LineItem(const QLineF &rect, const QPen &pen);
    6. private:
    7. int xvalue, yvalue;
    8. QPen pen;
    9. }
    To copy to clipboard, switch view to plain text mode 
    in lineitem.cpp
    Qt Code:
    1. LineItem::LineItem(const QLineF &line, const QPen &pen)
    2. pen(pen)
    3. {
    4. void LineItem ::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
    5. {
    6. painter->setPen(pen);
    7. painter->drawLine(line());
    8.  
    9. }
    To copy to clipboard, switch view to plain text mode 

    in graphicsview
    Qt Code:
    1. line1 = new LineItem(QLineF(2,4, 2 ,30), Qt::green);
    2. line1->setPos(100,550);
    3. scene->addItem(line1);
    To copy to clipboard, switch view to plain text mode 

    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




    }

  2. #2
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default 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

  3. The following user says thank you to talk2amulya for this useful post:

    wagmare (16th February 2009)

  4. #3
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    658
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Diff between QBrush and QPen

    thanks .. so i have to send QColor instead of QPen ...

  5. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Diff between QBrush and QPen

    Quote Originally Posted by wagmare View Post
    thanks .. so i have to send QColor instead of QPen ...
    If you want to sent a QColor why you define a constructor expecting a QPen? What's about defining:

    Qt Code:
    1. ...
    2. LineItem(const QLineF &rect, const QPen &pen);
    3. LineItem(const QLineF &rect, const QColor &color);
    4. LineItem(const QLineF &rect, const Qt::GlobalColor color);
    To copy to clipboard, switch view to plain text mode 

    with for example:

    Qt Code:
    1. LineItem(const QLineF &rect, const Qt::GlobalColor color)
    2. {
    3. pen = QPen(QColor(color));
    4. }
    To copy to clipboard, switch view to plain text mode 

    then you will be save.

  6. #5
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    658
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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

  7. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default 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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.