Qt QMenu remove drop shadow - qt

I have a QMenu with a translucent background and rounded edges (border-radius). Unfortunately, Windows 7 draws a drop shadow for this menu, which does not fit to the rounded edges. Its the shadow that would be drawn for normal rectangular menues.
Is there either
- a way to completely disable drawing drop shadows for QMenu
or
- a way to make the shadow fit to the rounded edges
?
Here is a minimalistic example where it occurs:
#include <QApplication>
#include <QPushButton>
#include <QMenu>
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
QPushButton b("press me");
QMenu m;
m.addAction("hello"); m.addAction("world");
m.setWindowFlags(m.windowFlags() | Qt::FramelessWindowHint);
m.setAttribute(Qt::WA_TranslucentBackground);
m.setStyleSheet("background:rgba(255,0,0,50%); border-radius:5px;");
b.setMenu(&m);
b.show();
return a.exec();
}

This should do it:
w.setWindowFlags(w.windowFlags() | Qt::NoDropShadowWindowHint);

Related

QT : QGraphicsTextItem alignment char to top-left corner

I want to draw a character aligned to the top-left corner of parent.
QGraphicsTextItem * tItem = new QGraphicsTextItem(parent);
tItem->setPlainText("a");
tItem->setPos(QPointF(0,0));
Picture below presents output of my code (grey rectangle is parent of QGraphicsTextItem)
Result:
I want to get a result like this:
My dream result:
I tried to use Qt::AlignLeft and Qt::AlignTop but to no avail.
The solution is to use setDocumentMargin(0) to the QTextDocument, if you only put the letter "a" it seems that it is not the solution since there seems to be a vertical offset, but in reality it is not an offset but the capital letters have a higher height.
Example:
#include <QApplication>
#include <QGraphicsTextItem>
#include <QGraphicsView>
#include <QTextDocument>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QGraphicsScene scene;
QGraphicsView view(&scene);
auto parent = scene.addRect(QRectF(0, 0, 100, 100), QPen(Qt::red), QBrush(Qt::blue));
auto * tItem = new QGraphicsTextItem(parent);
tItem->setPlainText("aAbB");
tItem->document()->setDocumentMargin(0);
view.show();
return a.exec();
}

How to play a video on a translucent QWidget?

I want to play a movie on a QWidget that has Qt::FramelessWindowHint flag and Qt::WA_TranslucentBackground attirbute using QVideoWidget or QGraphicsVideoItem. But the video is not visible. I hear only sound. What is the problem?
Edit:
#include "videoplayer.h"
#include <QtWidgets/QApplication>
#include "qboxlayout.h"
#include "qvideowidget.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget *w = new QWidget;
w->setWindowFlags(Qt :: Window | Qt::FramelessWindowHint );
w->setAttribute(Qt::WA_TranslucentBackground, true);
w->setMinimumSize(300,200);
QVideoWidget *videoWidget = new QVideoWidget;
QBoxLayout *controlLayout = new QHBoxLayout;
controlLayout->setMargin(0);
controlLayout->addWidget(videoWidget);
w->setLayout(controlLayout);
QMediaPlayer mediaPlayer;
mediaPlayer.setVideoOutput(videoWidget);
mediaPlayer.setMedia(QUrl::fromLocalFile("C:/1.wmv"));
videoWidget->show();
mediaPlayer.play();
w->show();
return app.exec();
}
I solve the problem .when we set the WA_TranslucentBackground flag and FramelessWindowHint attribute the QVideoWidget's QPainter going to QPainter::CompositionMode_DestinationOver mode and it cause to nothing to show or a shadow on the screen . in this case i use a custom video widget and in paintEvent after createing QPainter painter(this); add
painter.setCompositionMode(QPainter::RasterOp_SourceAndNotDestination); or
painter.setCompositionMode(QPainter::RasterOp_SourceAndDestination);
to change the composition mode.
I've implemented VideoWidget some time ago. The only thing you shall change is your video path and set FramelessWindowHint flag.
You can find source here.

Rotation should not work after applying QGraphicsItem::ItemIgnoresTransformation flag

I have three level of hierarchy of items on a GraphicsView:
An ellipse2 whose ItemIgnoresTransformations is OFF (parent GraphicsView)
an ellipse3 whose ItemIgnoresTransformations is ON (parent ellipse2)
a text Item whose ItemIgnoresTransformations is OFF (parent ellipse3)
So now I want To rotate textItem only when ellipse3 is rotated not when the whole view is rotated.
It is working fine in case of view rotation But when i rotated ellipse3 then text also rotates though its transformation is OFF Please explain me how it is possible??
#include <QApplication>
#include<QGraphicsView>
#include<QGraphicsScene>
#include<QGraphicsTextItem>
#include<QDebug>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QGraphicsView graphicsView;//Graphics View
QGraphicsScene graphicsScene;
graphicsView.setScene(&graphicsScene);
QGraphicsEllipseItem ellipse2(QRectF(0,0,4,4));//ellipseItem2
ellipse2.setFlags(QGraphicsItem::ItemIgnoresTransformations);
graphicsScene.addItem(&ellipse2);
QGraphicsEllipseItem ellipse3(QRectF(10,0,4,4),&ellipse2);//ellipseitem3
QGraphicsTextItem textItem("TEXT",&ellipse3);
textItem.setFlags(QGraphicsItem::ItemIgnoresTransformations);
textItem.setPos(10,0);
ellipse3.rotate(90);
graphicsView.show();
return a.exec();
}

Qt: QMenu with translucent background

I use Windows and I want to set a style sheet to a QMenu to give it a translucent background. In order for that to work, I first set the FramelessWindowHint, then I set the WA_TranslucentBackground attribute. Then I set my style sheet and display the menu with the popup method. It is drawn correctly, but it behaves strangely: As soon as it has the FramelessWindowHint, it is always visible (even before calling the popup() method). It does not hide itself anymore after one of its entries has been clicked.
Here is a minimalistic example:
#include <QApplication>
#include <QMenu>
#include <QPoint>
#include <QCursor>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMenu menu;
menu.addAction("about", &a, SLOT(aboutQt()));
menu.addAction("exit", &a, SLOT(quit()));
menu.setWindowFlags(Qt::FramelessWindowHint);
menu.setAttribute(Qt::WA_TranslucentBackground);
menu.setStyleSheet("QMenu{background:rgba(255, 0, 0, 50%);}");
menu.popup(QCursor::pos());
return a.exec();
}
menu.setWindowFlags(menu.windowFlags() | Qt::FramelessWindowHint);
should solve your problem. Now you are clearing all flags already set by Qt.

Qt: showFullScreen() on a QWidget doesn't remove Mac OSX Menu Bar

We get our application full screen alright, but the OSX Menu bar is still shown above it...
Is there any way around this problem?
Yes, might be a bug as already suggested. Try with FramelessWindowHint, like this:
#include <QtGui/QApplication>
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QLabel label("Test!");
label.setWindowFlags(Qt::FramelessWindowHint);
label.showFullScreen();
return a.exec();
}
I tested it on Mac OS X 10.7.1 (which is not even supported) and seems to work.

Resources