You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

spooky9

Beginner

  • "spooky9" is male
  • "spooky9" started this thread

Posts: 3

Location: Kraków

  • Send private message

1

Thursday, August 16th 2007, 11:14am

Another transparent widget

Hello,
I'm trying to achieve an effect that is presented in the attached screenshot.
The idea is to have a semi transparent widget that will be a container for other graphical widgets, and will be displayed on top of a text edit widget, so that the text from underneeth is visible.
My first idea to do this, was to use QGraphicsView/QGraphicsScene classes, but I wasn't able to get transparency with these. Images that were placed in the QGraphicsScene were transparent, but the context of the text editor was not visible.

Could someone give me a hint what will be the best way to do this?
I am currently considering the usage of QSvgRenderer or writing a custom widget, though this will require to implement the 'storage' machanizm that is allready available in QGraphicsScene.

If it is possible to achieve this effect with QGraphicsView/QGraphicsScene, I'd appreciate a code fragment.

Any help will be appreciated.
spooky9 has attached the following file:
  • oow3.png (157.06 kB - 306 times downloaded - latest: Feb 5th 2011, 6:04pm)

bolt18_80

Intermediate

  • "bolt18_80" is male

Posts: 186

Location: Ohio, US

Occupation: Programmer/Analyst

  • Send private message

2

Friday, August 17th 2007, 2:43am

RE: Another transparent widget

Assuming you're using Qt4...

The QWidget class has a window opacity property that you can set and get with...

void setWindowOpacity(qreal)
qreal windowOpacity() const

in case you're not familiar with qreal...on most platforms it's a typedef for double.

the windowOpacity can be set to a level from 0.0 (complete transparent) to 1.0 (complete opaque).

please post or read the qt documentation if you have further questions.

Chris
Christopher Springer
Programmer/Analyst
NBEC/NWOCA - Ohio SSDT
Website: http://www.moderncpp.org
cspringer@moderncpp.org

spooky9

Beginner

  • "spooky9" is male
  • "spooky9" started this thread

Posts: 3

Location: Kraków

  • Send private message

3

Saturday, August 18th 2007, 11:39am

I've tried setWindowOpacity() with no result, maybe the attached project will help to find the solution.
spooky9 has attached the following file:
  • tran.tar.bz2 (1.59 kB - 58 times downloaded - latest: Feb 5th 2011, 6:04pm)

4

Saturday, August 18th 2007, 12:12pm

Well, you can still use QColor alpha.

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Tran::Tran(QMainWindow *parent)
	: QMainWindow(parent)
{
	setupUi(this);

	//Action approach
	createActions();

	scene = new QGraphicsScene(this);
	scene->setBackgroundBrush(QColor(255, 255, 0, 255/2));

	helperView = new QGraphicsView(scene, this);
	helperView->move(20, 20);
	//helperView->setWindowOpacity(0.5); // for me also not working
  QPalette pal = helperView->palette();
  QColor c = pal.color(QPalette::Base);
  c.setAlphaF(0.5);
  pal.setColor(QPalette::Base, c);
  helperView->setPalette(pal);
//	helperView->setFrameStyle(QFrame::NoFrame | QFrame::Plain);
	helperView->setMaximumSize(this->width() - 40, this->height() - this->statusbar->height() - 40);
	helperView->resize(this->width() - 40, this->height() - this->statusbar->height() - 40);
	helperView->setBackgroundRole(QPalette::Base);

  QGraphicsScene *scene = new QGraphicsScene(this);
  c.setRed(0);
  QPen pen(c);
  QBrush brush(c);
  scene->addEllipse(0.0, 0.0, 200.0, 200.0, pen, brush);
  
  helperView->setScene(scene);
}


Maybe it is not what you want.
Fighting fire with fire.
Three can keep a secret if two of them are dead.

spooky9

Beginner

  • "spooky9" is male
  • "spooky9" started this thread

Posts: 3

Location: Kraków

  • Send private message

5

Monday, August 20th 2007, 11:00pm

Thanks for the tip! worked like a charm :)