How to add the OS X flavor to a Qt app - c++

I have used Qt previously only in the form of PyQt, and today I tried the original version of Qt in C++.
I got it working, however, when if start up my app, I have several problems with it:
it's stationary, which means, I cannot drag it across the screen
I cannot change the size of the window
it does not have a OS X type status bar (which contains the three colored buttons and the name of the window)
How can I add these features to my C++ Qt app?
I have tried to look for a solution, but only found QtApplication::setStyle();, which did not solve my problem.
You can see the code here.

The code inside your subclass of QMainWindow contains this line:
setWindowFlags(Qt::FramelessWindowHint);
That is probably causing most of the problems you describe. Try removing that line.

Related

How to create an Evernote kind of widget for global menu of a MacOS/X desktop using QT?

How to create an application which stays in top of MacOS, something similar to below image. You can see the Evernote elephant icon.
I don't want to use xcode - because my application already built in QT, it has nice GUI, now I wanted to add extended feature something similar to Evernote. If I click on an elephant it will open a dialog box to write notes. In my case- it's a simple event like on/off buttons.
I have tried and created GUI widget apps but how to make one which resides like Evernote app ?
A custom pop up menu like the one pictured can be done several ways in Qt.
QML is the most modern way of making the menu with the customized styling you are looking for.
Apply the appropriate flags to the window/widget so it appears as a popup.
The same effects can also be done in QWidgets, but takes more code and probably will take longer to make. The flags you are looking for will be found under Qt Window Flags and/or under Qt Widget Attributes.
The stock stylings for Qt for different OS's deal mostly with title bars, status bars, buttons, drop downs, etc.
The base styles for Mac can be found here:
http://doc.qt.io/qt-5/gallery-macintosh.html
Once you go to a customized popup, you have to draw all of it yourself... but the native drawing elements in Qt are friendly enough and get you that look you are trying to do.
There are even some tools for exporting from Photoshop or Gimp directly to QML.
http://doc.qt.io/qtcreator/quick-export-to-qml.html
Hope that helps.
You are looking for a tray icon. Qt implements it in QSystemTrayIcon.
Further information
You may take a look at the System Tray Icon Example.
Many StackOverflow posts exist on this topic.
If you already have a program written for Qt, then you can compile and run it under MacOS/X much the same way you could compile it under (whatever OS you're using now). You'll need to install Xcode because Xcode includes the C++ compiler (clang) you'll need in order to compile your Qt program, but you don't have to use the Xcode IDE if you don't want to. Rather, you can either use the QtCreator IDE under MacOS/X, or you can simply open up a Terminal window and do a "qmake ; make" in the directory where your Qt-based program's .pro file is, and build it from the command line that way.
If, on the other hand, your question is actually about how to add an icon to the global menu of a MacOS/X desktop, then I don't think Qt has an API for that, so you'll need to drop down to using one of MacOS/X's native APIs. That will probably involve learning some Objective-C (or Objective-C++, if you prefer), but integrating a bit of Objective-C/C++ into your Qt app is doable with a bit of work.

QT QApplication:setFont() Questions

In my main.cpp I set the font of the application like so:
//Font
QString fontPath = ":/data/COUR.TTF";
int id = QFontDatabase::addApplicationFont(fontPath);
QString family = QFontDatabase::applicationFontFamilies(id).at(0);
QFont default_font(family);
default_font.setPointSize(10);
QApplication::setFont(default_font);
This works, mostly. For whatever reason all of the application that I can see correctly applies this font except for the very parent widget, QTabWidget.
I also have this snippet of code that is activated on a button press, inside a MainWindow function:
QApplication::setFont(QFontDialog::getFont(0, QApplication::font()));
When activated during runtime, this error is produced:
2017-06-13 21:10:14.622 MYAPP[36930:4140590] Layout still needs update after calling -[QNSPanelContentsWrapper layout].
QNSPanelContentsWrapper or one of its superclasses may have overridden -layout without calling super.
Or, something may have dirtied layout in the middle of updating it. Both are programming errors in Cocoa Autolayout.
The former is pretty likely to arise if some pre-Cocoa Autolayout class had a method called layout, but it should be fixed.
(Edited a little for visual clarity)
I've looked at this bug report, which shows the exact same error and a similar-ish code, it may be relevant: https://bugreports.qt.io/browse/QTBUG-58699
Their code:
QColorDialog::getColor(QColor(1., 1., 1.), myWindow, "My Title", QColorDialog::DontUseNativeDialog);
That error is not produced by the MainWindow function if I remove the main.cpp settings, which makes me doubt its actually this bug. In addition, the MainWindow function correctly applies the font chosen to all but a few (seemingly) random buttons.
They (From the bug report) are on OSX 10.11.6, I am as well. They reported it for QT 5.8, I'm experiencing it with QT 5.9 and 5.8. If this is the case, this doesn't surprise me, as the bug report does not indicate it has been fixed. I can reproduce it on the QT Creator built debug version, and a statically built release version.
So my question boils down to these points:
1) Why does the main.cpp font code not work across all widgets?
2) Why does that MainWindow function not override the main.cpp settings?
3) Why does that MainWindow function (With the main.cpp part removed) not apply the settings to the entire application?
4) Are there better/easier ways to accomplish what I'm trying to do? (Set a font on application start, and provide a way for the user to customize it later)

GTK3: version 3.20 to 3.22 update issues (with window decoration)

I recently updated the GTK3 lib I am using, both on windows and linux,
from version 3.20 to 3.22, and I noticed some bugs in my application (GTK3 + OpenGL using the GtkGLArea widget) appearing after the update.
The bug, namely the disappearance of window decoration appears after a precise, yet simple, succession of events:
1) screen shot before the bug:
2) Exporting an image from this window (using a framebuffer for off-screen rendering)
3) After saving, going back to the main window by closing the dialog box, note that the upper menu bar now appears like if de-activated (grey) but sill works:
4) ... and when re-sizing / hiding / showing again 'ie. configuring' the window the decoration disappear:
5) The menu bar still seems to be there and works fine:
Obviously I looked carefully to the code after the saving action, but what happens remain elusive to me and I do not know what to look for.
The program does not stop and keeps working fine.
There was absolutely no problem with GTK3 3.20, and the bug appears both on windows and Linux.
What can I do to correct this situation ?
In the Gtk-3 series there have been many changes to the CSS system. If you are not using the default Adwaita theme, then probably you have to search for an updated version of the theme you do have installed. It might even be possible that the Adwaita theme wasn't update correctly during your upgrade.
Anyway, nearly all appearance problems are due to changes in the CSS system - Gtk doesn't really occupy itself with the aesthetics anymore.

Qt: QVideoWidget doesn't show up and disables all buttons within application OR extremely slows down the application

To make it clear the question is: Why, when I add a QVideoWidget to my application, all buttons become not clickable, the scrollbars don't work, and the comboboxes as well become not clickable? Is QVideoWidget disabling those functionalities? Or is that maybe (like I read in this SO question) QVideoWidget is extremely slowing down my application, just by being added to the application?
Now the details:
I really hope someone can help me with this. I'm trying to place a QvideoWidget into my desktop application with the following code (nothing special, just like in the tutorials):
// ...
// more code above for other things...
// main video-player widget
video_widget = new QVideoWidget;
video_widget->setMaximumHeight(100); // I could set any size here...this is not the point
video_widget->setMinimumHeight(100);
video_widget->setStyleSheet(STYLE_WIDGET_BG); // same background as the other widgets...
video_widget->setMaximumWidth(100);
video_widget->setMinimumWidth(100);
media_player = new QMediaPlayer(0, QMediaPlayer::VideoSurface);
TV_V_LAYOUT_MAIN_2->addWidget(video_widget); // #define TV_V_LAYOUT_MAIN_2 ui.lvl_4_tv2_h_1 --> this a layout inside another layout...
media_player->setVideoOutput(video_widget);
return; // this function is called inside the MainWindow constructor
So there are the situations:
1) Without adding the videowidget, everything works fine...
2) As soon as I add the QVideoWidget with the code above:
app overview
What happens?
The video player doesn't show up in any way. There should be at least the gray background like the other widgets, but nothing. Yet the buttons position lowers, so I guess the player was inserted...The problem is: all buttons (and I mean ALL buttons within my application) are disabled. So are the comboboxes and the scrollbar. By disabled I mean, when you click them, it doesn't normally "animate" like when a button is cliked, and the scrollbar doesn't scroll...
By the way the QVideoWidget is not places into the same layout as the buttons below. You can see the layout hierarchy here: Layouts with Qt Designer
I guess I'm missing something very simple. Anyone got the solution for me?
INFO: I'm programming with Visual Studio 2013 with Qt Add-In; I use only standard libraries; gstreamer is included in the project as well (nothing implemented yet).
OLD EDIT: it may be that the inserting of the video-widget extremely slows down the application, therefore giving the illusion that the scrollbar and the buttons don't work, just because it takes a lot of time for them to process the user interaction. Is this possible? Any solution for that?
Got the solution:
If your QVideoWidgets or QMediaPlayers extremely slow down your application, all you have to do, if you haven't yet, is to move all (or just the nedeed) Qt dll's into your project folder.
That's very basic, I know, yet that was my problem. Now it works like heaven.

Qt 5 Mac toolbar woes

I am trying to make a very simple toolbar in a QMainWindow on a Mac, with Qt 5.2.1, with not a single satisfaction. I was using still Qt 4.8 but I thought I'd give Qt5 a try.
As QtMacExtras are concerned, I don't find the native toolbar class anymore, except in private headers. So I tried a simple QToolbar.
I have a very basic and stupid toolbar:
setUnifiedTitleAndToolBarOnMac(true);
toolbar_ = new QToolBar(this);
toolbar_->setMovable(false);
toolbar_->setFloatable(false);
toolbar_->addAction("h");
toolbar_->addAction("w");
toolbar_->addSeparator();
toolbar_->addAction("f");
As you can see, well, it isn't acceptable.
Is there any chance, by some arcane and weird means, that I could have a nice unified, or better "native look and feel", toolbar on a mac?
QMainWindow::addToolBar(QToolBar *toolbar) should do it.
The NSToolbar does not form part of the Qt widget hierarchy, so your admirably idiomatic conference of parenthood from the main window to the toolbar is working perfectly to specification, yet is obviously dissatisfying.
However, as the Trolls say in the QMainWindow documentation:
"You add a toolbar to a main window with addToolBar()."
Here is the effect as shown in rsync client for Mac.
I don't have my mac with me otherwise I would give this a quick test. I was surprised when browsing how many bugs are still being reported for Mac. I did find this article, which does appear to have better looking toolbar.