QFrame and QMainWindow
-
Hello everyone! I'm trying to set up over my main window translucent darkened "glass" like lightbox or something like that.
Ok, I reached this by this code:
@QFrame *f = new QFrame;
f->setFrameStyle(QFrame::Box | QFrame::Plain);
f->setWindowOpacity(0.5);
f->setGeometry(this->geometry());
f->setWindowFlags(Qt::FramelessWindowHint);
f->setLineWidth(200);
f->show();@Result:
!http://pastexen.com/i/sgqsyzhp.png(Result)!But now frame is like another window:
!http://pastexen.com/i/P6Zpj19Q.png(Taskbar)!Ofcouse it will not resize and move with my main window. If I will set this-parent in constructor of QFrame it will be incorrect result:
!http://pastexen.com/i/XthE9vvO.png(Incorrect result)!What I can do with this to reach my goal?
-
[quote author="ByteWight" date="1367185042"]I believe this is your problem:
@f->setWindowFlags(Qt::FramelessWindowHint);@
That's what makes your frame a window. Maybe you want this instead?
@f->setFrameShape(QFrame::NoFrame);@
[/quote]
Yea, thank you very much, main problem was in that -
Hmm. Now new problem. I want to put in the center of frame widget, but if it's widget parent will be not frame - it will be inactive under it. If set frame as parent - it will be transparent like frame, but I need to set it opaque:
@
this->setFrameStyle(QFrame::Box | QFrame::Plain);
this->setWindowOpacity(0.6);
this->setFrameShape(QFrame::Box);
@
!http://pastexen.com/i/HDFLYd08.png(Transparent)!
What can I do, guys? -
@this->setWindowOpacity(0.6);@
You keep using these window functions when you shouldn't. They should only be used on window or dialog boxes. How about you try a stylesheet instead?
@this->setStyleSheet("QFrame { background: rgba(255, 255, 255, 128); }");@
(I did not test this out, but it should theoretically work)
-
[quote author="ByteWight" date="1367273842"]@this->setWindowOpacity(0.6);@
You keep using these window functions when you shouldn't. They should only be used on window or dialog boxes. How about you try a stylesheet instead?
@this->setStyleSheet("QFrame { background: rgba(255, 255, 255, 128); }");@
(I did not test this out, but it should theoretically work)[/quote]
Now it is (=( have no idea why ):
!http://s019.radikal.ru/i640/1304/aa/da60122e334e.png(Now)! -
Instead of a window over top of the main window why not subclass paintEvent. Maybe something like this:
@
void MyWindow::paintEvent(QPaintEvent *event)
{
QPainter painter(this);QMainWindow::paintEvent(event); // allow parent class to draw window painter.fillRect(event->rect(),QColor(255,255,255,128)); //translucent color
}
@Edit: Never mind. This won't do what you want.
-
Any other ideas? :(((