Page 1 of 2 12 LastLast
Results 1 to 20 of 32

Thread: How to Transparent QGraphicsView widget Background?

  1. #1
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default How to Transparent QGraphicsView widget Background?

    Dear Everyone!
    How to Transparent QGraphicsView widget background?
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to Transparent QGraphicsView widget Background?

    What did you try so far?
    Qt Code:
    1. graphicsView->setStyleSheet("background: transparent");
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. #3
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to Transparent QGraphicsView widget Background?

    Quote Originally Posted by jpn View Post
    What did you try so far?
    Qt Code:
    1. graphicsView->setStyleSheet("background: transparent");
    To copy to clipboard, switch view to plain text mode 
    I have tried this one earlier as you suggested.But It sets the Background WHITE not a Tranparent.
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to Transparent QGraphicsView widget Background?

    Works for me with Qt 4.3.2.
    J-P Nurmi

  5. #5
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to Transparent QGraphicsView widget Background?

    Quote Originally Posted by jpn View Post
    Works for me with Qt 4.3.2.
    Dear Sir!

    I am using the following code in Qt 4.3.2.

    Qt Code:
    1. QGraphicsTextItem *scrItem = new QGraphicsTextItem(scrText);
    2. scrItem->setDefaultTextColor(QColor(Qt::red));
    3.  
    4.  
    5. animation->setItem(scrItem);
    6. float n;
    7. screen=QApplication::desktop()->screenGeometry();
    8. int yLoc=screen.height()-(scrFont.pointSize()+40);
    9. wScroller->setGeometry(0,yLoc,wScroller->width(),scrFont.pointSize()+40);
    10. view=new QGraphicsView(scene,wScroller);
    11. view->setWindowFlags (Qt::FramelessWindowHint);
    12. view->setStyleSheet("background: transparent");
    13. scene->addItem(ship);
    14. scene->addItem(scrItem);
    15.  
    16. view->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
    17. view->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
    18. view->setCacheMode(QGraphicsView::CacheBackground);
    19.  
    20. scene->setSceneRect(0,0,wScroller->width(),scrFont.pointSize()+40);
    21. n=scrWidth;/*Width of scrText*/
    22.  
    23. qreal sh=scene->height()/2-ship->boundingRect().height()/2;
    24. qreal h=scene->height()/2-scrItem->boundingRect().height()/2; /*Calculating the eaxact mid Y cordinate position of scrItem (Text)*/
    25.  
    26.  
    27. register int scrItembrw=scrItem->boundingRect().width();
    28. register int velNum=16;
    29. register int velocity=(((velNum-scrSpeed)*3)-2);
    30. register int tl=(n+scrItembrw)*velocity;
    31. scrTime=tl;
    32.  
    33. timer = new QTimeLine(tl);
    34. timer->setCurveShape(QTimeLine::LinearCurve);
    35. timer->setLoopCount(0);
    36. animation->setTimeLine(timer);
    37. animation1->setTimeLine(timer);
    38.  
    39.  
    40. for (int i=0; i<(n+scrItem->boundingRect().width()); i=i+1)
    41. {
    42. QPointF p(0,h);
    43. p.setX(n-i);
    44. p.setY(h);
    45. ps.setX(n-i-imgbrw);
    46. ps.setY(sh);
    47. animation->setPosAt(i/(n+scrItem->boundingRect().width()),p);
    48.  
    49. }//end for
    50.  
    51. view->setFixedWidth(wScroller->width());
    52. view->setFixedHeight(scene->height());
    53. view->show();
    54. timer->start();
    To copy to clipboard, switch view to plain text mode 

    but it is not working.
    Last edited by jpn; 9th December 2007 at 10:34. Reason: changed [quote] to [code]
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to Transparent QGraphicsView widget Background?

    Give the following example a try:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication app(argc, argv);
    6. QMainWindow window;
    7.  
    8. QGraphicsScene* scene = new QGraphicsScene(&window);
    9. QGraphicsItem* item = scene->addText("QGraphicsTextItem");
    10. item->setFlags(QGraphicsItem::ItemIsMovable);
    11.  
    12. QGraphicsView* view = new QGraphicsView(&window);
    13. view->setStyleSheet("background: transparent");
    14. view->setScene(scene);
    15.  
    16. window.setCentralWidget(view);
    17. window.setStyleSheet("background: green");
    18. window.show();
    19. return app.exec();
    20. }
    To copy to clipboard, switch view to plain text mode 
    As you can see, the background of the main window shows through the view.

    Quote Originally Posted by ashukla View Post
    Qt Code:
    1. view=new QGraphicsView(scene,wScroller);
    2. view->setWindowFlags (Qt::FramelessWindowHint);
    To copy to clipboard, switch view to plain text mode 
    What are you trying to accomplish with this? You pass a parent so it's not a top level widget you could remove window frames from. If you actually want to adjust transparency of a top level widget, take a look at QWidget::setWindowOpacity() but make sure you read the notes in docs.
    J-P Nurmi

  7. #7
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to Transparent QGraphicsView widget Background?

    Quote Originally Posted by jpn View Post
    Give the following example a try:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication app(argc, argv);
    6. QMainWindow window;
    7.  
    8. QGraphicsScene* scene = new QGraphicsScene(&window);
    9. QGraphicsItem* item = scene->addText("QGraphicsTextItem");
    10. item->setFlags(QGraphicsItem::ItemIsMovable);
    11.  
    12. QGraphicsView* view = new QGraphicsView(&window);
    13. view->setStyleSheet("background: transparent");
    14. view->setScene(scene);
    15.  
    16. window.setCentralWidget(view);
    17. window.setStyleSheet("background: green");
    18. window.show();
    19. return app.exec();
    20. }
    To copy to clipboard, switch view to plain text mode 
    As you can see, the background of the main window shows through the view.


    What are you trying to accomplish with this? You pass a parent so it's not a top level widget you could remove window frames from. If you actually want to adjust transparency of a top level widget, take a look at QWidget::setWindowOpacity() but make sure you read the notes in docs.
    Dear Sir!
    Actually, I have designed three QX11EmbedContainer widget (as a child namely f1,f2,f3 dynamically) of QX11Container parent widget. I am playing in f1 & f2 frames different movies and in the third f3 child widget I want to play scrolling text like news with transparent background.
    for which I am using the above code.

    QScrollerViewPlayer::QScrollerViewPlayer(QString file, int width, int height, QWidget *wscr)
    {
    scrHeight = height;
    scrWidth = width;
    scrFileName = file;
    wScroller=wscr;
    }
    what should I do for trasprenting widget in that context.
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to Transparent QGraphicsView widget Background?

    Quote Originally Posted by ashukla View Post
    and in the third f3 child widget I want to play scrolling text like news with transparent background.
    I have a widget for that...

  9. #9
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Question Re: How to Transparent QGraphicsView widget Background?

    Quote Originally Posted by wysota View Post
    I have a widget for that...
    Dear Sir!

    What is the full feature of that widget?
    How to get this widget?
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

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

    Default Re: How to Transparent QGraphicsView widget Background?

    It's a widget that scrolls a QTextDocument. I haven't tried it with a transparent background, but it's probably possible

    The widget is not available for public, I have some issues with speed stability I need to fix before releasing it. But in general I render the document to a pixmap and then render the pixmap to the widget with different offsets, depending on the step of the animation.

  11. #11
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to Transparent QGraphicsView widget Background?

    Quote Originally Posted by wysota View Post
    It's a widget that scrolls a QTextDocument. I haven't tried it with a transparent background, but it's probably possible

    The widget is not available for public, I have some issues with speed stability I need to fix before releasing it. But in general I render the document to a pixmap and then render the pixmap to the widget with different offsets, depending on the step of the animation.
    OK Sir!
    But In my context; How a way I set the transparency of widget.
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to Transparent QGraphicsView widget Background?

    I think J-P already gave you some hints. Did you follow them?

  13. #13
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to Transparent QGraphicsView widget Background?

    Quote Originally Posted by wysota View Post
    I think J-P already gave you some hints. Did you follow them?
    Yes! I have followed them. But I am not getting the desired output.
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  14. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to Transparent QGraphicsView widget Background?

    What is the desired output? Do you want to show it over another widget or over desktop?

  15. #15
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to Transparent QGraphicsView widget Background?

    Quote Originally Posted by wysota View Post
    What is the desired output? Do you want to show it over another widget or over desktop?
    Dear Sir!
    I have explained earlier as follows
    I have designed three QX11EmbedContainer widget (as a child namely f1,f2,f3 dynamically) of QX11Container parent widget. I am playing in f1 & f2 frames different movies and in the third f3 child widget I want to play scrolling text like news with transparent background.
    for which I am using the above code.
    I want to play scroll text upon the running movie background.
    That means I want to play text scroller with tranparent background.
    What should I do for that?
    Thanking in advance to give suggestion!
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  16. #16
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to Transparent QGraphicsView widget Background?

    I want to show it over another widget.
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  17. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to Transparent QGraphicsView widget Background?

    It might not work, because the embedded widget is really another application, so drawing over it might be difficult. And because that other widget is a movie, it might be even more difficult - usually one uses overlays for that. I suggest you find some other solution (for example don't embed external applications).

  18. #18
    Join Date
    Apr 2009
    Posts
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to Transparent QGraphicsView widget Background?

    Hi, I am attempting the same thing, but simpler.
    I would like to place a QGraphicsView over the top of (a child of) another plain QWidget. I have tried:

    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication app(argc, argv);
    6. QMainWindow window;
    7.  
    8. QGraphicsScene* scene = new QGraphicsScene(&window);
    9. QGraphicsItem* item = scene->addText("QGraphicsTextItem");
    10. item->setFlags(QGraphicsItem::ItemIsMovable);
    11.  
    12. QGraphicsView* view = new QGraphicsView(&window);
    13. view->setStyleSheet("background: transparent");
    14. view->setScene(scene);
    15.  
    16. window.setCentralWidget(view);
    17. window.setStyleSheet("background: green");
    18. window.show();
    19. return app.exec();
    20. }
    To copy to clipboard, switch view to plain text mode 

    but it results in a white window, not a green one. The QGraphicsView refuses to become transparent.

    I've tried this in Qt for win32 4.4.0 and 4.4.3.
    Anyone have any ideas? Thanks!
    Last edited by jpn; 24th April 2009 at 07:40. Reason: missing [code] tags

  19. #19

    Default Re: How to Transparent QGraphicsView widget Background?

    Qt Code:
    1. QBrush brBrush;
    2.  
    3. QPalette palette(brBrush,brBrush,brBrush,brBrush,brBrush,brBrush,brBrush,brBrush,brBrush);
    4.  
    5. setPalette(palette);
    6.  
    7. setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);
    8.  
    9. setAttribute(Qt::WA_TranslucentBackground);
    10.  
    11. setFrameShape(QFrame::NoFrame);
    To copy to clipboard, switch view to plain text mode 

    try this, with Qt 4.5

  20. #20
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Platforms
    Unix/X11 Windows

    Default Re: How to Transparent QGraphicsView widget Background?

    Hi,

    I encounter the same issue. Thanks to jpn answer i managed to see the mainwindow background under my graphicsview.
    Now, is there an easy way to make the central widget transparent. I mean : to obtain a QMainWindow with toolbar and menubar and borders, but where we see desktop and other windows in place of central widget. I'm looking for a solution for some times now but can't find anything helpful

    Note : in my app, this would allow the user to draw something, using the QGraphicsView as a tracing paper

Similar Threads

  1. Graphics widget with background
    By ad5xj in forum Newbie
    Replies: 2
    Last Post: 24th August 2007, 16:29
  2. Creating a widget on a QGraphicsView
    By maverick_pol in forum Qt Programming
    Replies: 4
    Last Post: 9th August 2007, 17:54
  3. transparent background of the main widget
    By nagpalma in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2007, 17:52
  4. Replies: 3
    Last Post: 8th December 2006, 18:51
  5. Replies: 1
    Last Post: 5th April 2006, 16:44

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.