Dear Everyone!
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!
What did you try so far?
Qt Code:
graphicsView->setStyleSheet("background: transparent");To copy to clipboard, switch view to plain text mode
J-P Nurmi
Works for me with Qt 4.3.2.
J-P Nurmi
Dear Sir!
I am using the following code in Qt 4.3.2.
Qt Code:
animation->setItem(scrItem); float n; int yLoc=screen.height()-(scrFont.pointSize()+40); wScroller->setGeometry(0,yLoc,wScroller->width(),scrFont.pointSize()+40); view->setWindowFlags (Qt::FramelessWindowHint); view->setStyleSheet("background: transparent"); scene->addItem(ship); scene->addItem(scrItem); view->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); view->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); scene->setSceneRect(0,0,wScroller->width(),scrFont.pointSize()+40); n=scrWidth;/*Width of scrText*/ qreal sh=scene->height()/2-ship->boundingRect().height()/2; qreal h=scene->height()/2-scrItem->boundingRect().height()/2; /*Calculating the eaxact mid Y cordinate position of scrItem (Text)*/ register int scrItembrw=scrItem->boundingRect().width(); register int velNum=16; register int velocity=(((velNum-scrSpeed)*3)-2); register int tl=(n+scrItembrw)*velocity; scrTime=tl; timer->setLoopCount(0); animation->setTimeLine(timer); animation1->setTimeLine(timer); for (int i=0; i<(n+scrItem->boundingRect().width()); i=i+1) { p.setX(n-i); p.setY(h); ps.setX(n-i-imgbrw); ps.setY(sh); animation->setPosAt(i/(n+scrItem->boundingRect().width()),p); }//end for view->setFixedWidth(wScroller->width()); view->setFixedHeight(scene->height()); view->show(); 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 11:34. Reason: changed [quote] to [code]
Anurag Shukla
A man who never makes mistake is the man who never does anything! Theodre Rosvelt!
Give the following example a try:
As you can see, the background of the main window shows through the view.Qt Code:
#include <QtGui> int main(int argc, char *argv[]) { QMainWindow window; view->setStyleSheet("background: transparent"); view->setScene(scene); window.setCentralWidget(view); window.setStyleSheet("background: green"); window.show(); return app.exec(); }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
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.
what should I do for trasprenting widget in that context.QScrollerViewPlayer::QScrollerViewPlayer(QString file, int width, int height, QWidget *wscr)
{
scrHeight = height;
scrWidth = width;
scrFileName = file;
wScroller=wscr;
}
Anurag Shukla
A man who never makes mistake is the man who never does anything! Theodre Rosvelt!
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.
I think J-P already gave you some hints. Did you follow them?
What is the desired output? Do you want to show it over another widget or over desktop?
Dear Sir!
I have explained earlier as followsI want to play scroll text upon the running movie background.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.
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!
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!
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).
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:
#include <QtGui> int main(int argc, char *argv[]) { QMainWindow window; view->setStyleSheet("background: transparent"); view->setScene(scene); window.setCentralWidget(view); window.setStyleSheet("background: green"); window.show(); return app.exec(); }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 08:40. Reason: missing [code] tags
Qt Code:
QBrush brBrush; setPalette(palette); setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint); setAttribute(Qt::WA_TranslucentBackground); To copy to clipboard, switch view to plain text mode
try this, with Qt 4.5
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
Bookmarks