Results 1 to 6 of 6

Thread: QTextEdit on top of QGraphicsView, not QGraphicsScene

  1. #1
    Join Date
    Oct 2010
    Posts
    37
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default QTextEdit on top of QGraphicsView, not QGraphicsScene

    I have a QGraphicsView and want to add a QTextEdit on top of that, which resizes with the whole window. I parent it to the view, instead of the scene since the text needs to remain the same size.

    screen.jpg


    Qt Code:
    1. def resizeEvent(self, event):
    2. # .....
    3. winSize = self.contentsRect().size()
    4. winw, winh = winSize.width(), winSize.height()
    5. self.chat.resize(winw*0.5, winh*0.5)
    6. self.chat.move(10,winh*0.5)
    To copy to clipboard, switch view to plain text mode 

    At the moment I resize it manually in the resizeEvent, but it's ugly since when you resize it updates and when scrollbars appear, it becomes transparent and I don't know how to turn it off.

    How should I be doing this?

    It's as if the widget has no 'sense' of the size of the window. If I could attach another widget to the window layered on top of the QGraphicsView below then this could be easily be solved by using layouts.

    window.setWidget(QGraphicsScene); window.setWidget2(interactableGui)

    That sort of thing
    Last edited by genjix; 30th October 2010 at 22:38.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QTextEdit on top of QGraphicsView, not QGraphicsScene

    Quote Originally Posted by genjix View Post
    I parent it to the view, instead of the scene since the text needs to remain the same size.
    Eeem... would you care to explain what you mean by this?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Maemo/MeeGo
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Re: QTextEdit on top of QGraphicsView, not QGraphicsScene

    Ok im not sure this will help but i thought i should say i think the QGraphicsScene is just a collection of data with accessors and mutators (methods) no visual element. the graphics view is the widget that shows the scene if you get what i mean.


    if i am wrong feel free to tell me as i am learning to.

  4. #4
    Join Date
    Oct 2010
    Posts
    37
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Re: QTextEdit on top of QGraphicsView, not QGraphicsScene

    If you parent it to the scene, then when you resize the window (and hence the view), the text will get smaller (and the box as a whole).

    If you parent it to the view, then the whole box gets smaller with the text remaining the same size. Although then I am needing to resize the box manually inside resizeEvent since it seems to have no sense of it's parent's size.

  5. #5
    Join Date
    Oct 2010
    Posts
    37
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Re: QTextEdit on top of QGraphicsView, not QGraphicsScene

    someone told me I have to use QGraphicsLayout. Here's what was said on the ML for others:
    Qt Code:
    1. Well for a start you never mentioned that you were using QGraphicsView. In
    2. fact you specifically said "widget".
    3.  
    4. Secondly, you can still use a QGraphicsLayout subclass. In this case set the
    5. layout on a parent QGraphicsWidget rather than a QWidget.
    6.  
    7. This will *NOT* rescale your content but will only alter the size of your
    8. QGraphicsWidget. I do this all of the time so I know that it works.
    9.  
    10. If you can still not get this to work please post a small *compilable* example
    11. that shows the problem and we can help to modify it to make it work.
    12.  
    13. Cheers,
    14.  
    15. Sean
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QTextEdit on top of QGraphicsView, not QGraphicsScene

    I'm still not sure I understand what you mean (resizing the window doesn't cause any resizing of any of the items on its own, you have to implement it yourself) but I think that you might want to set the ItemIgnoresTransformations flag on the text edit item.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QGraphicsScene & QGraphicsView help please
    By munna in forum Qt Programming
    Replies: 6
    Last Post: 13th February 2017, 13:30
  2. QGraphicsView and QGraphicsScene
    By alisami in forum Qt Programming
    Replies: 8
    Last Post: 4th December 2008, 11:10
  3. QGraphicsScene and QGraphicsView
    By sabeesh in forum Qt Programming
    Replies: 7
    Last Post: 1st August 2007, 07:59
  4. QGraphicsScene and QGraphicsView
    By rossd in forum Qt Programming
    Replies: 2
    Last Post: 25th April 2007, 15:43
  5. (QT4.2-RC1) QGraphicsScene QGraphicsView QGraphicsItem
    By antonio.r.tome in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2006, 11:56

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.