PDA

View Full Version : Problem Q3Scrollview along with Q3Painter while porting



davids81
29th June 2012, 10:47
Hi,
I am in the process of porting my code from qt3.3 to qt4.7, and am facing a issue while drawing a line using Q3painter over Q3Scrollview.
In my application all the paintings are done on viewport widget of QScrollView(Q3ScrollView in support class).
i have class graphview which is inherited from Q3Scrollview, and i have widgets for x & y axis on it. i want to draw a line parallel to x-axis with regular interval on y-axis.



GraphView::GraphView(
int min, int max, QWidget* parent, const char* name, Qt::WFlags f
) : Q3ScrollView(parent,name,f|Qt::WResizeNoErase|Qt:: WStaticContents),
vscale(1.0),
hscale(1.0),
oVscale(1.0),
oHscale(1.0),
hZoom(1.0),
vZoom(1.0), manscale(false), marker(100),
zoomPop(this),
crossCursor(Qt::CrossCursor),waitCursor(Qt::WaitCu rsor)
{
leftMark=0; rightMark=0; doingStatistics=false;statsInProgress=0;
if(max < min) max = min;
minval = min;
maxval = max;
setDragAutoScroll(true);
valsPerReport=1;
xLine = 0;
viewport()->setEraseColor(QColor("white"));
update_from_move = false;
yAxis = new Axis(minval, maxval, true, this);
xAxis = new Axis(this);
xAxisHeight = ((QWidget*)xAxis)->sizeHint().height();
yAxisWidth = ((QWidget*)yAxis)->sizeHint().width();
//hide - the rectangle outside the axis - down and left
hide = new QWidget(this);
hide->setBackgroundColor(QColor("white"));
hide->lower();
hide->stackUnder(yAxis);
hide->stackUnder(xAxis);
setMargins(yAxisWidth,0,0,xAxisHeight);
QRect r = viewport()->geometry();
yAxis->setGeometry(r.x()-yAxisWidth,r.y(),yAxisWidth,r.height());
hide->setGeometry(r.x()-yAxisWidth,r.y()+r.height(),yAxisWidth-1,xAxisHeight);
xAxis->setGeometry(r.x()-1,r.y()+r.height(),r.width()+1,xAxisHeight);
conX = contentsX();
conY = contentsY();
resizeContents(1, (int)((maxval-minval)*vscale));
center(0,0); //ensureVisible
size = 0;
visibleSize = visibleWidth();
newScrolling= false;
updSize = 1;
connect(this, SIGNAL( horizontalSliderReleased() ), this, SLOT(processNewXPosition() ) );
viewport()->setCursor(Qt::CrossCursor);
reloadCounter=0;
gVector.push_back(this);
}

//in resize event i am trying to draw line on yaxis, but i don't see the output.

void GraphView::viewportResizeEvent( QResizeEvent* re) {

// resize the axis widgets
QRect r = viewport()->geometry();
yAxis->setOffset(contentsY());
yAxis->setGeometry(r.x()-yAxisWidth,r.y(),yAxisWidth,r.height());
xAxis->setOffset(contentsX());
xAxis->setGeometry(r.x()-1,r.y()+r.height(),r.width()+1,xAxisHeight);
hide->setGeometry(r.x()-yAxisWidth,r.y()+r.height(),yAxisWidth-1,xAxisHeight);
QSize os = re->oldSize();

if(os.width() < r.width() && r.width() > ((int)size/hscale-contentsX())) {
QPainter painter(viewport());
int y = ((int)((double)maxval - (double)contentsY()/vscale))%marker;
if(marker*vscale>5){
painter.setPen(QColor("grey"));
for(; y < r.height(); y+=marker) {
double yd = y * vscale;
painter.drawLine(os.width(),(int)yd,r.width()-1,(int)yd);
update();//added newly for graph issue
}

}
}
setContentsPos ( contentsX(), contentsY()+os.height()-r.height() );
}


i am getting the window with x and y axis but not the grey lines on y axis.
Please let me what am missing here, is anything needs to be considered while using Qpainter on Q3Scrollview?

Thx
Dav