Using KDE System Theme in Pure Qt Application - c++

I'm developing a Qt4 app and running it under gnome, but I would really like it to use a KDE system theme (Oxygen) and color scheme (Obsidian Coast). Unfortunately, the application doesn't seem to respond to changes in systemsettings.
I am at least able to get the app to use the theme I want programmatically by setting the QStyle:
QApplication app( argc, argv );
app.setStyle(QStyleFactory::create("oxygen"));
but I don't know of any similar approach for setting the color scheme, and this is kind of ugly anyway.
Interestingly, I've already developed some PyQt4 apps on this same machine and they pick up changes in systemsettings just fine. I'm not really sure why a C++ Qt4 app would behave differently.
One more note: I've noticed that changing the window appearance via the gnome dialog will affect my C++ qt window's appearance - so perhaps Gnome is overriding my KDE configuration somehow?

The only solution I've found is to let the environment do the work for you, as noted here: https://forum.kde.org/viewtopic.php?f=17&t=90720
A snip from the posts:
So you wish to start Amarok with a different colour scheme to the rest of KDE?
You can do this by having a different set of settings for it.
Open Konsole, and enter "export KDEHOME=$HOME/.kde4-amarok/"
Then run "systemsettings" and configure how you would like Amarok to appear ( colour scheme, etc. )
Finally, run "amarok" to start Amarok itself.
This will work for QT applications as well, but you can't set the style from within the application like you're trying (app.setStyle(QStyleFactory::create("oxygen");) You'll have to use a slightly messier method:
sys.argv.append("--style=Oxygen")
This will read the argument from the environment, and won't make a whole new Oxygen theme instance, (assuming you've set the KDEHOME environment to somewhere in your project, and you've already customized that) and will then use that KDEHOME to read the colors from and use the Oxygen theme.
Maybe they'll change this for QT5... (The ability to set a style programmatically)

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.

Backgroung color toolbar and menubar in windows 7

I want to change the backgroung color of the toolbar and the menu bar of my application in Windows 7.
I have this look:
but I want this look:
So I'd like to know - this problem is connected with Visual Styles, and can be solved with some functions / changes of color scheme of application or I should write my own classes and set the particular color in RGBenter image description here.
If you have any example code, I would glad to see it.
As Cody indicated, you need to use visual styles. When you create a new project in Visual Studio, you’re given the opportunity to specify a visual style.
The new application uses the CMFCVisualManager class to render the individual UI components.
CMFCVisualManager...
Provides support for changing the appearance of your application at a
global level. The CMFCVisualManager class works together with a class
that provides instructions to draw the GUI controls of your
application using a consistent style.
If you’re dealing with an existing application, you would need to add the VisualManager class to your code. I would suggest you create a sample application and look at the code that gets generated. Once you understand how the code works, you can port what you need to your application.

QT How to embed an application into QT widget

In our project we have three independent applications, and we have to develop a QT control application that controls these three applications. The main window will be seperated to three sub windows - each one display another one application.
I thought to use QX11EmbedWidget and QX11EmbedContainer widgets, but two problems with that:
The QX11Embed* is based on X11 protocol and I dont know if it's supported on non-x11 systems like Windows OS.
Since QT 5 these classes are not existing, and the QT documentation doesn't mention why.
So that I dont know whether to use it or not - I'll be happy to get an answers.
In addition, I see that the QT 5.1 contains QWidget::createWindowContainer(); function that in some posts it looks like this should be the replacement to the X11Embed. Can anyone please explian me more how can I use this function to create a QT widget that will run another application (a Calculator for example) inside its?
I have searched a lot in Google, and didn't find answers to my Qs.
Can anyone please help me? Am I on the right way?
Thanks!
If all three independent applications are written with Qt, and you have their source, you should be able to unify them just through the parenting of GUI objects in Qt.
http://qt-project.org/doc/qt-4.8/objecttrees.html
http://qt-project.org/doc/qt-4.8/widgets-and-layouts.html
http://qt-project.org/doc/qt-4.8/mainwindows-mdi.html
If you don't have access to them in that way, what you are talking about is like 3rd party window management. It is kind of like writing a shell, like Windows Explorer, that manipulates the state and the size of other window applications.
Use a program like Spy++ or AutoIt Spy for Windows and the similar ones for other OS's, and learn the identifying markings of your windows you want to control, like the class, the window title, etc. Or you can launch the exe yourself in a QProcess::startDetached() sort of thing.
http://qt-project.org/doc/qt-5.1/qtcore/qprocess.html#startDetached
Then using the OS dependent calls control the windows. The Qt library doesn't have this stuff built in for third party windows, only for ones under the QApplication that you launched. There are a lot of examples of doing things like this by AutoHotKey, or AHK. It is a scripting language that is made for automating a lot of things in the windows environment, and there is port for Mac as well (though I haven't tried the mac port myself).
So in the end you are looking at finding your window probably with a call like this:
#include <windows.h>
HWND hwnd_1 = ::FindWindow("Window_Class", "Window Name");
LONG retVal = GetWindowLongA(hwnd_1, GWL_STYLE); // to query the state of the window
Then manipulate the position and state of the window like so:
::MoveWindow(hwnd_1, x, y, width, height, TRUE);
::ShowWindow(hwnd_1, SW_SHOWMAXIMIZED);
You can even draw widgets on top of the windows you are controlling if you set your window flags correctly for the windows you are manipulating.
transparent QLabel with a pixmap
Cannot get QSystemTrayIcon to work correctly with activation reason
Some gotchas that come up in Windows when doing all of this, is finding out the quirks of the Windows UI when they set the Display scaling different from what you expect, and if you want to play nice with the Task bar, and handling all the modal windows of your programs you are manipulating.
So overall, it is do-able. Qt will make a nice interface for performing these commands, but in the end you are looking at a lot of work and debugging to get it in a beautiful, reliable, window manager.
Hope that helps.
I never tried it myself, but from the docs in Qt 5.1 I would try QWindow::fromId(WId id), which gives you a QWindow, which should be embeddable with createWindowContainer:
QWindow * QWindow::fromWinId(WId id) [static] Creates a local
representation of a window created by another process or by using
native libraries below Qt.
Given the handle id to a native window, this method creates a QWindow
object which can be used to represent the window when invoking methods
like setParent() and setTransientParent(). This can be used, on
platforms which support it, to embed a window inside a container or to
make a window stick on top of a window created by another process.
But no guarantee. :-)

Virtual Keyboard in Linux/GTK

I have a simple interface (Can be touch-based or can be operated by mouse clicks). When I select a text box, a virtual keyboard should pop up. I have done a little digging, and xvkbd looks nice. X11 is the only dependency, which is fine! However, I do not want to install a keyboard in a system and call it issuing commands or set environment variables. I want the keyboard to be a part of the application I make, and it should pop up when I run the application and select a text box, and under no other circumstances. As I gather, coding a virtual keyboard from scratch is not the easiest of tasks. If there is something I could use in my C++ application, it would be really nice. Please advise.
Check matchbox-keyboard, it should do what you need with gtk.
Taken from its README
Embedding
You can embed matchbox-keyboard into other applications with toolkits that support the XEMBED protocol ( GTK2 for example ).
See examples/matchbox-keyboard-gtk-embed.c for how its done.
You could use QX11EmbedContainer, if you have access to Qt. If not, you can embed the xvkbd's window yourself (see here how).

Terminal to open a popup window in C++

My c++ application needs to display a message via a popup window or an alternative. My application is running on Ubuntu 12.04 version. Can I program the application to open a Ubuntu type popup window? If possible, how?
Do I need to use gnome window or something like that?
The simplest way to display a popup from a program that doesn't otherwise use a GUI, is probably just execute a command-line tool that does the work:
to display a notification with no buttons, you can use notify-send
system("/usr/bin/notify-send MessageSubject \"message body here\"");
if you want buttons so the user can give a response, you could use the (much uglier) xmessage
system("/usr/bin/xmessage")
(see each tool's manpage for all their options)
The alternative is really to use a full GUI framework (probably gtk+), and that's not typically a small change.
For example, you can use libnotify directly (giving you the same basic capabilities as notify-send, but more control), but this also depends on glib. So, now you've added two external dependencies when you could just have run system.
In order to display the popup or any kind of window, you will have to reference either gtk+ or qt libraries in your application/program. gtk+ is advisable, since the ubuntu unity desktop is also based on gtk+ - this way your program will have lesser overhead and more performance gain while running on ubuntu. You can either use the default C library (libgtk2.0) or the gtkmm (libgtkmm) for C++.
You can get more information on how to refer these libraries, initialize gtk_main in your main() function, etc. at this place: http://www.gtk.org/documentation.php