-
Notifications
You must be signed in to change notification settings - Fork 0
/
qgraphicstableitem.cpp
70 lines (62 loc) · 2.61 KB
/
qgraphicstableitem.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "qgraphicstableitem.h"
#include "tablecolumn.h"
QGraphicsTableItem::QGraphicsTableItem( TableColumn *parentCol,
TableItem *parentItem, int xPos,
int yPos, int width, int height,
QPen borderPen, QBrush fillBrush,
QString text, QColor textColor,
QFont textFont )
: //初始化自己,并指定自己的parent TableColumn
QGraphicsRectItem( xPos, yPos, width, height, parentCol ),
parentColumnPtr( parentCol ), parentItemPtr( parentItem ),
//初始化child,指定自己为他们的parent
backgroundItemPtr(
new QGraphicsRectItem( xPos, yPos, width, height, this ) ),
textItemPtr( new QGraphicsTextItem( text, backgroundItemPtr ) ) {
backgroundItemPtr->setPen( borderPen );
backgroundItemPtr->setBrush( fillBrush );
backgroundItemPtr->setZValue( 3 );
textItemPtr->setDefaultTextColor( textColor );
textItemPtr->setPos( xPos, yPos );
textItemPtr->setTextWidth( width );
textItemPtr->setFont( textFont );
textItemPtr->setZValue( 4 );
}
void QGraphicsTableItem::paint( QPainter * painter,
const QStyleOptionGraphicsItem *option,
QWidget * widget ) {
backgroundItemPtr->paint( painter, option, widget );
textItemPtr->paint( painter, option, widget );
}
void QGraphicsTableItem::show() {
// QGraphicsRectItem::show();
backgroundItemPtr->show();
textItemPtr->show();
}
void QGraphicsTableItem::hide() {
// QGraphicsRectItem::hide();
backgroundItemPtr->hide();
textItemPtr->hide();
}
void QGraphicsTableItem::resize( QResizeEvent *tableEvent ) {
//设置自己
QGraphicsRectItem( ClassTable::scaleSize( this->rect(), tableEvent ) );
//设置背景
backgroundItemPtr->setRect(
ClassTable::scaleSize( backgroundItemPtr->rect(), tableEvent ) );
//设置文字
textItemPtr->setPos(
ClassTable::scaleSize( textItemPtr->pos(), tableEvent ) );
textItemPtr->setTextWidth( textItemPtr->textWidth()
* tableEvent->size().width()
/ tableEvent->oldSize().width() );
}
void QGraphicsTableItem::resize( int xPos, int yPos, int width, int height ) {
//设置自己
QGraphicsRectItem( xPos, yPos, width, height );
//设置背景
backgroundItemPtr->setRect( xPos, yPos, width, height );
//设置文字
textItemPtr->setPos( xPos, yPos );
textItemPtr->setTextWidth( width );
}