Results 1 to 1 of 1

Thread: Problem Q3Scrollview along with Q3Painter while porting

  1. #1
    Join Date
    Jun 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Problem Q3Scrollview along with Q3Painter while porting

    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.

    Qt Code:
    1. GraphView::GraphView(
    2. int min, int max, QWidget* parent, const char* name, Qt::WFlags f
    3. ) : Q3ScrollView(parent,name,f|Qt::WResizeNoErase|Qt::WStaticContents),
    4. vscale(1.0),
    5. hscale(1.0),
    6. oVscale(1.0),
    7. oHscale(1.0),
    8. hZoom(1.0),
    9. vZoom(1.0), manscale(false), marker(100),
    10. zoomPop(this),
    11. crossCursor(Qt::CrossCursor),waitCursor(Qt::WaitCursor)
    12. {
    13. leftMark=0; rightMark=0; doingStatistics=false;statsInProgress=0;
    14. if(max < min) max = min;
    15. minval = min;
    16. maxval = max;
    17. setDragAutoScroll(true);
    18. valsPerReport=1;
    19. xLine = 0;
    20. viewport()->setEraseColor(QColor("white"));
    21. update_from_move = false;
    22. yAxis = new Axis(minval, maxval, true, this);
    23. xAxis = new Axis(this);
    24. xAxisHeight = ((QWidget*)xAxis)->sizeHint().height();
    25. yAxisWidth = ((QWidget*)yAxis)->sizeHint().width();
    26. //hide - the rectangle outside the axis - down and left
    27. hide = new QWidget(this);
    28. hide->setBackgroundColor(QColor("white"));
    29. hide->lower();
    30. hide->stackUnder(yAxis);
    31. hide->stackUnder(xAxis);
    32. setMargins(yAxisWidth,0,0,xAxisHeight);
    33. QRect r = viewport()->geometry();
    34. yAxis->setGeometry(r.x()-yAxisWidth,r.y(),yAxisWidth,r.height());
    35. hide->setGeometry(r.x()-yAxisWidth,r.y()+r.height(),yAxisWidth-1,xAxisHeight);
    36. xAxis->setGeometry(r.x()-1,r.y()+r.height(),r.width()+1,xAxisHeight);
    37. conX = contentsX();
    38. conY = contentsY();
    39. resizeContents(1, (int)((maxval-minval)*vscale));
    40. center(0,0); //ensureVisible
    41. size = 0;
    42. visibleSize = visibleWidth();
    43. newScrolling= false;
    44. updSize = 1;
    45. connect(this, SIGNAL( horizontalSliderReleased() ), this, SLOT(processNewXPosition() ) );
    46. viewport()->setCursor(Qt::CrossCursor);
    47. reloadCounter=0;
    48. gVector.push_back(this);
    49. }
    50.  
    51. //in resize event i am trying to draw line on yaxis, but i don't see the output.
    52.  
    53. void GraphView::viewportResizeEvent( QResizeEvent* re) {
    54.  
    55. // resize the axis widgets
    56. QRect r = viewport()->geometry();
    57. yAxis->setOffset(contentsY());
    58. yAxis->setGeometry(r.x()-yAxisWidth,r.y(),yAxisWidth,r.height());
    59. xAxis->setOffset(contentsX());
    60. xAxis->setGeometry(r.x()-1,r.y()+r.height(),r.width()+1,xAxisHeight);
    61. hide->setGeometry(r.x()-yAxisWidth,r.y()+r.height(),yAxisWidth-1,xAxisHeight);
    62. QSize os = re->oldSize();
    63.  
    64. if(os.width() < r.width() && r.width() > ((int)size/hscale-contentsX())) {
    65. QPainter painter(viewport());
    66. int y = ((int)((double)maxval - (double)contentsY()/vscale))%marker;
    67. if(marker*vscale>5){
    68. painter.setPen(QColor("grey"));
    69. for(; y < r.height(); y+=marker) {
    70. double yd = y * vscale;
    71. painter.drawLine(os.width(),(int)yd,r.width()-1,(int)yd);
    72. update();//added newly for graph issue
    73. }
    74.  
    75. }
    76. }
    77. setContentsPos ( contentsX(), contentsY()+os.height()-r.height() );
    78. }
    To copy to clipboard, switch view to plain text mode 

    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
    Last edited by davids81; 29th June 2012 at 10:58.

Similar Threads

  1. scrollbar not working in Q3ScrollView...
    By sh123 in forum Qt Programming
    Replies: 0
    Last Post: 12th February 2009, 09:13
  2. Q3ScrollView resists to scroll down to the garbage bin
    By sivrisinek in forum Qt Programming
    Replies: 0
    Last Post: 5th February 2009, 17:50
  3. QT3 porting to QT4 problem
    By batileon in forum Newbie
    Replies: 3
    Last Post: 7th June 2008, 23:58
  4. Q3ScrollView
    By veda in forum Qt Programming
    Replies: 2
    Last Post: 19th November 2007, 06:29
  5. Porting problem from Qt3 to Qt4
    By Krishnacins in forum Qt Programming
    Replies: 2
    Last Post: 19th May 2006, 14:29

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.