View Full Version : How can i write a text background of my treewidget using QPainter?
newermind
29th April 2009, 13:54
How can i write a text background of my treewidget using QPainter?
I am using QT 4.5...
spirit
29th April 2009, 14:05
do you need to change text color?
I don't understand what you want.
newermind
29th April 2009, 14:30
i want to show a text background-treewidget. Not color.
spirit
29th April 2009, 14:32
still don't understand. :)
Lykurg
29th April 2009, 14:36
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.
newermind
29th April 2009, 14:40
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
spirit
29th April 2009, 14:45
you must draw in QWidget:: paintEvent.
newermind
29th April 2009, 15:00
void QWidget::paintEvent(QPaintEvent *)
{
QPainter p;
p.begin( tree_widget );
p.drawText( 5, 5, QString("Something"));
p.end();
}
ERROR:
The program has unexpectedly finished.
spirit
29th April 2009, 15:03
cool!
if you want to draw on a tree widget you must:
-- subclass QTreeWidget/QTreeView and reimplement paintEvent;
...
void MyTreeWidget::paintEvent(QPaintEvent *e)
{
QTreeWidget::paintEvent(e);
QPainter p(this);
//drawing stuff
}
...
-- install event filter on a tree widget and process QPaintEvent.
...
m_treeWidget->viewport()->installEventFilter(this);
...
bool MyWidget::eventFilter(QObject *o, QEvent *e)
{
if (o == m_treeWidget->viewport() && e->type() == QEvent::Paint) {
QPainter p(m_treeWidget->viewport());
//draw stuff
}
return QWidget::eventFilter(o, e);
}
newermind
29th April 2009, 15:14
Sorry, i don`t understand .
have you got an example code about this problem?
spirit
29th April 2009, 15:17
I updated a post above.
newermind
29th April 2009, 15:31
thanks.. it`s worked... :):):):)
newermind
29th April 2009, 15:41
how can i refresh this event filter or painter?
Now it`s working when programme started.
spirit
29th April 2009, 15:51
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.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.