Results 1 to 4 of 4

Thread: QGraphicsView get fullscreen

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2010
    Posts
    22
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default QGraphicsView get fullscreen

    Hi all,

    I'm tring to develop a calendar like those of Outlook, or Google Calendar. To do that I'm using a QGraphicsView, QGraphicsScene and QGraphicsItem(s). At the moment I draw a grid that represents hours, so there is a solid line for each hour and a dotline for each half hour. I developed it with a small monitor, and when I render it with a bigger one my QGraphicsView is bigger than my scene. So there is white space on both left and right side of my graph. I'm going to attach a picture to show the defect. I tried to use this code to fix:

    Qt Code:
    1. void GraphicsView::populateScene()
    2. {
    3. m_scene = new QGraphicsScene(this);
    4. setScene(m_scene);
    5. qDebug() << "scene rect: " << m_scene->sceneRect();//this prints: "scene rect: QRectF(0,0 0x0)"
    6. fitInView(m_scene->sceneRect());
    7. qDebug() << "scene rect: " << m_scene->sceneRect();//this prints: "scene rect: QRectF(0,0 0x0)"
    8. drawGrid();
    9. this->fitInView(m_scene->sceneRect());
    10. qDebug() << "scene rect: " << m_scene->sceneRect();//and finally this works: "scene rect: QRectF(-0.5,-0.5 1001x1153) "
    11. //Use ScrollHand Drag Mode to enable Panning
    12. setDragMode(ScrollHandDrag);
    13. }
    To copy to clipboard, switch view to plain text mode 

    so as far as I can understand only last fitInView call works, but after that call the view is empty, while if I remove that call I get what you can see in attached picture.

    This is the code I used to obtain that grid:

    Qt Code:
    1. void GraphicsView::drawGrid()
    2. {
    3. const int linesNumber = 48;
    4. int counter=0;
    5. qreal leftLine=0.0;
    6. qreal y = 0;
    7. qreal gridSize = m_fontFactor * 2;
    8. QTime time;
    9. QFont textFont("Times New Roman", m_fontFactor);
    10. QPen redPen(QColor(255, 0, 0, 127),1.0,Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin);
    11. QPen halfHourPen(QColor(201,201,201, 255),1.0,Qt::DotLine,Qt::RoundCap,Qt::RoundJoin);
    12. QPen hourPen(QColor(201, 201, 201, 255),1.0,Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin);
    13. m_eventRect = QRectF();
    14. for(int i=counter;i<linesNumber;i++)
    15. {
    16. if(i%2==0)
    17. {//draw hour line:
    18. time.setHMS(counter++,0,0);
    19. item = m_scene->addText(time.toString("hh:mm"),textFont);
    20. item->setPos(10, y);//set up text's position
    21. if(leftLine == 0.0)
    22. leftLine = item->boundingRect().width();
    23. m_scene->addLine(0,y,1000,y,hourPen);
    24. m_lines[i] = QRectF(leftLine+11,y+1,1000-5,gridSize-2);
    25. }else{//draw half hour line:
    26. m_scene->addLine(leftLine+10,y,1000,y,halfHourPen);
    27. m_lines[i] = QRectF(leftLine+11,y+1,1000-5,gridSize-2);
    28. }
    29. y += gridSize;
    30. }
    31. m_scene->addLine(leftLine+10,0,leftLine+10,y,redPen);
    32. m_eventRect.setX(0.0);
    33. m_eventRect.setY(0.0);
    34. m_eventRect.setWidth(1000.0);
    35. m_eventRect.setHeight(y);
    36.  
    37. slotUpdateHourHighlightLine();
    38. setSceneRect(0, 0, 1000, y);
    39. }
    To copy to clipboard, switch view to plain text mode 

    m_lines is a QVector<QRectF> used to store where coords' line, so I can use them later in my code (to attach an event with a fixed hour/half hour position)
    How can I get size to avoid using "magic numbers" into my code? I mean how to get a width to always has a fullscreen graph? and how to draw always a fullscreen graph?
    Thanks for any reply.
    Alberto
    Attached Images Attached Images

Similar Threads

  1. cannot exit from fullscreen
    By lazycoder in forum Qt Programming
    Replies: 1
    Last Post: 7th October 2011, 06:38
  2. Fullscreen in qml
    By vinayaka in forum Newbie
    Replies: 2
    Last Post: 3rd October 2011, 07:05
  3. QGraphicsItem to fullscreen
    By medved6 in forum Qt Programming
    Replies: 2
    Last Post: 16th June 2010, 22:54
  4. QMenu bar in FullScreen
    By ppaluch in forum Newbie
    Replies: 0
    Last Post: 14th August 2009, 15:52
  5. Fullscreen
    By dragor in forum Qt Programming
    Replies: 1
    Last Post: 21st February 2006, 21:23

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
  •  
Qt is a trademark of The Qt Company.