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

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.

Related

QVideoWidget: Video is cut off

I want to play a video in a Qt Application. This is my code so far:
#include <QApplication>
#include <QWidget>
#include <QMediaPlayer>
#include <QVideoWidget>
#include <QUrl>
#include <iostream>
using namespace std;
const int WIDTH = 1280;
const int HEIGHT = 720;
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget window;
window.resize(WIDTH, HEIGHT);
window.setWindowTitle("Video Test");
window.show();
QMediaPlayer *player = new QMediaPlayer();
player->setMedia(QUrl::fromLocalFile("/Path/To/Video.mp4"));
QVideoWidget *videoWidget = new QVideoWidget(&window);
player->setVideoOutput(videoWidget);
videoWidget->resize(WIDTH, HEIGHT);
videoWidget->show();
player->play();
return app.exec();
}
The problem: The video is shown and plays back normally, but the video does not resize to fit in the QVideoWidget. The part of the video that is bigger than the widget is cut off.
Thanks in advance!
EDIT: I reduced the code and noticed, that when the application starts the video is cut off, but when I resize the window using the mouse it actually fits to the size:
#include <QApplication>
#include <QWidget>
#include <QMediaPlayer>
#include <QVideoWidget>
#include <QUrl>
#include <iostream>
using namespace std;
const int WIDTH = 1280;
const int HEIGHT = 720;
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QMediaPlayer *player = new QMediaPlayer();
QVideoWidget *videoWidget = new QVideoWidget();
player->setVideoOutput(videoWidget);
player->setMedia(QUrl::fromLocalFile("/Path/To/Video.mp4"));
player->play();
videoWidget->resize(WIDTH/3, HEIGHT/3);
videoWidget->show();
return app.exec();
}
For anyone in 2016, QVideoWidget is still busted. However, use a QGraphicsView widget, which holds a scene graph, and add a single QGraphicsVideoItem to the scene graph. Seems to work...
well, except that it's not exactly centered. and there's a 1px border on the left. and it hangs going into full screen most of the time. and I get errors like "updateVideoFrame called without AVPlayerLayer (which shouldn't happen". Progress!
.. oh, and it takes up about 10x the cpu too.
You know what does work, and works great? GStreamer. Thank you, gstreamer. Even integrating it in python/qt works fabulously.
I ran into a similar problem in PyQt5. I worked around it by setting the geometry of the QVideoWidget to its current geometry before playing the video. I am guessing something in the resizeEvent signal must handle the scaling of the media and isn't triggered when initialized.
After many hours of looking for the error, I think this is a bug in Qt on OSX, as I watched this YouTube video https://www.youtube.com/watch?v=tGKmQy-VBX0 and tried out the code.
In the video scaling works fine, but on my machine not.
After playing, I resized the QVideoWidget by 1 and then resized to original size.
Definitely "fudge", but this works for me until I find a real solution:
(working with PyQt5 and High Sierra)
s1 = self.MediaFrame.size() # QVideoWidget
s2 = s1 + QSize(1, 1)
self.MediaPlayer.play() # QMediaPlayer
self.MediaFrame.resize(s2) # enlarge by one pixel
self.MediaFrame.resize(s1) # return to original size
Usually the scale mode dictates how the video fills the widget.
The scale mode FitInView will force the video to fill the view keeping aspect ratio.
However, this scale mode should be the default. You can try to set it manually:
QVideoWidget *videoWidget = new QVideoWidget(&window);
videoWidget->setScaleMode(Phonon::VideoWidget::FitInView);
player->setVideoOutput(videoWidget);
If you still searching for a solution to this, QVideoWidget class has setAspectRatioMode method. Use this to scale frames of video to fit your widget area.

I got errors: "QQmlApplicationEngine failed to load component" and "qrc:/main.qml:-1 File not found"

I created a Qt Widgets application, then added a qml named "main.qml" to it. My files are dialog.cpp, dialog.h, dialog.ui, main.cpp, untitiled9.pro, main.qml in qml.qrc
main.cpp:
#include "dialog.h"
#include <QApplication>
#include <QQmlApplicationEngine>
#include<QtQml>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Dialog w;
// w.show();
QQmlApplicationEngine engine;
// engine.load(QUrl(QStringLiteral("qrc://main.qml")));
engine.load(QUrl::fromLocalFile("qrc:///main.qml"));
return a.exec();
}
I wrote QT += qml quick widgets in untitled9.pro.
I didn't modified other codes, how did this happen?
This is my first question in stackoverflow, I try to make my question clear.
QUrl::fromLocalFile will build a local file based url. So, just remove "qrc:///" in the code. Copy main.qml into build target directory if necessary.
Sample code:
engine.load(QUrl::fromLocalFile("main.qml"));

Set text direction for QLabel?

Is there a way to set the text direction for a QLabel? I've got a situation in which I have QLabel objects whose text is only punctuation, and I want that to be displayed either in RTL or LTR format. (For instance, parentheses or quotation marks need to reverse depending on the text direction.) I've tried calling QLabel::setLayoutDirection, but to no effect.
#include <QApplication>
#include <QLabel>
int main(int argc, char **argv)
{
QApplication app (argc, argv);
QLabel label(" :  «");
label.setFont( QFont("Times New Roman", 72) );
label.setLayoutDirection( Qt::RightToLeft );
// label.setLayoutDirection( Qt::LeftToRight );
label.show();
return app.exec();
}
A workaround at this point is to prepend 0x202E ("Right-to-Left Override") to the string, but that's obviously a bit clunky.
label.setAlignment(Qt::AlignRight);

Qt QMenu remove drop shadow

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);

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.

Resources