Results 1 to 14 of 14

Thread: How can i write a text background of my treewidget using QPainter?

  1. #1
    Join Date
    Apr 2009
    Location
    İstanbul, Türkiye
    Posts
    26
    Thanks
    1

    Default How can i write a text background of my treewidget using QPainter?

    How can i write a text background of my treewidget using QPainter?

    I am using QT 4.5...

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How can i write a text background of my treewidget using QPainter?

    do you need to change text color?
    I don't understand what you want.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Apr 2009
    Location
    İstanbul, Türkiye
    Posts
    26
    Thanks
    1

    Default Re: How can i write a text background of my treewidget using QPainter?

    i want to show a text background-treewidget. Not color.

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How can i write a text background of my treewidget using QPainter?

    still don't understand.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. #5
    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: How can i write a text background of my treewidget using QPainter?

    If I get you, you want a text as a background. Then use a QPainter to create a QPixmap with your favored text and set that QPixmap as a background image.

  6. #6
    Join Date
    Apr 2009
    Location
    İstanbul, Türkiye
    Posts
    26
    Thanks
    1

    Default Re: How can i write a text background of my treewidget using QPainter?

    QPainter p;

    p.begin( tree_widget );

    p.drawText( 5, 60, QString("Something"));

    p.end();

    i wrote this code but it`s not worked .

    ERORR:
    QPainter::begin: Widget painting can only begin as a result of a paintEvent
    QPainter::end: Painter not active, aborted

  7. #7
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How can i write a text background of my treewidget using QPainter?

    you must draw in QWidget:: paintEvent.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  8. #8
    Join Date
    Apr 2009
    Location
    İstanbul, Türkiye
    Posts
    26
    Thanks
    1

    Default Re: How can i write a text background of my treewidget using QPainter?

    void QWidget:aintEvent(QPaintEvent *)
    {
    QPainter p;

    p.begin( tree_widget );

    p.drawText( 5, 5, QString("Something"));

    p.end();

    }

    ERROR:

    The program has unexpectedly finished.

  9. #9
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How can i write a text background of my treewidget using QPainter?

    cool!
    if you want to draw on a tree widget you must:
    -- subclass QTreeWidget/QTreeView and reimplement paintEvent;
    Qt Code:
    1. ...
    2. void MyTreeWidget::paintEvent(QPaintEvent *e)
    3. {
    4. QTreeWidget::paintEvent(e);
    5. QPainter p(this);
    6. //drawing stuff
    7. }
    8. ...
    To copy to clipboard, switch view to plain text mode 
    -- install event filter on a tree widget and process QPaintEvent.
    Qt Code:
    1. ...
    2. m_treeWidget->viewport()->installEventFilter(this);
    3. ...
    4. bool MyWidget::eventFilter(QObject *o, QEvent *e)
    5. {
    6. if (o == m_treeWidget->viewport() && e->type() == QEvent::Paint) {
    7. QPainter p(m_treeWidget->viewport());
    8. //draw stuff
    9. }
    10. return QWidget::eventFilter(o, e);
    11. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by spirit; 29th April 2009 at 16:16.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  10. #10
    Join Date
    Apr 2009
    Location
    İstanbul, Türkiye
    Posts
    26
    Thanks
    1

    Default Re: How can i write a text background of my treewidget using QPainter?

    Sorry, i don`t understand .

    have you got an example code about this problem?

  11. #11
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How can i write a text background of my treewidget using QPainter?

    I updated a post above.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  12. #12
    Join Date
    Apr 2009
    Location
    İstanbul, Türkiye
    Posts
    26
    Thanks
    1

    Default Re: How can i write a text background of my treewidget using QPainter?

    thanks.. it`s worked...

  13. #13
    Join Date
    Apr 2009
    Location
    İstanbul, Türkiye
    Posts
    26
    Thanks
    1

    Default Re: How can i write a text background of my treewidget using QPainter?

    how can i refresh this event filter or painter?

    Now it`s working when programme started.

  14. #14
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How can i write a text background of my treewidget using QPainter?

    do you mean how to chage a text which will be drawn?
    have a look at example which is located in QTDIR/examples/widgets/wiggly.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 10:49
  2. QLineEdit and background text
    By SnarlCat in forum Qt Programming
    Replies: 2
    Last Post: 6th March 2009, 23:17
  3. Drawing Rich Formatted Text with QPainter
    By millsks in forum Qt Programming
    Replies: 1
    Last Post: 5th March 2009, 20:59
  4. How to write some text next to the system tray icon?
    By alex chpenst in forum Qt Programming
    Replies: 3
    Last Post: 5th September 2008, 09:43
  5. Rich text with QPainter?
    By sarefo in forum Qt Programming
    Replies: 3
    Last Post: 7th April 2008, 15:40

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.