Results 1 to 20 of 32

Thread: How to Transparent QGraphicsView widget Background?

Hybrid View

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

    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
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    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
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11
    Thanks
    8
    Thanked 14 Times in 14 Posts

    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
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    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
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11
    Thanks
    8
    Thanked 14 Times in 14 Posts

    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
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    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
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11
    Thanks
    8
    Thanked 14 Times in 14 Posts

    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,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: 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
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11
    Thanks
    8
    Thanked 14 Times in 14 Posts

    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,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: 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
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11
    Thanks
    8
    Thanked 14 Times in 14 Posts

    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!

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