Adding Menu bar to QT cvNameWIndow - c++

I am trying to create video-player application with open CV using QT creator. using openCV it is possible to play video files by adding each video frame as an image on an instance of cvNamedWindow.
Now I would like to add a menu bar to this cvNamedWindow so that I can add File, help etc menus. menus. I looked up the documentation of cvNamedWindow and I couldn't find any clue. Any suggestions?
P.s. In opencv windows created using QMainWindow, it is straightforwaed to add menu bar. But what I want is to add the menu bar to cvNamedWindow not to a window created using QMainWindow.

OpenCV's user interface is quite limited, so there's no way to accomplish what you are looking for with OpenCV's API.
On the other hand, Qt has a rich API for building graphic applications. Luckily for you, I just shared cvVideo: an example that demonstrates how to play videos on a QWidget surface. Plus, the demo has some neat tricks to change aspect ratio modes. Almost forgot, it displays a simple QMenuBar too.

you can use createButton and createTrackbar with namedWindow, but that's it.
sure, you could simulate a menu with a row of buttons, but if you need something more advanced,
stick to the native Qt api.

Related

How to create a menubar in SFML application?

I'm trying to write an SFML 2.5.1 program, but I have faced an issue, I can't find in the internet how to create working program menubar, which is located upper window (or upper screen in Mac OS), something like this:
All I have found in the internet is a Titlebar, only first two options in menubar: File and Edit, and they are don't work for some reason, don't reacting on clicking, I can't find out why.
Help me please
You can hide the original title bar and make your own using classes (button or titlebar_button, call it as u want) which is just a rectangle shape with the on_Click function.
https://en.sfml-dev.org/forums/index.php?topic=24051.0 - Answer
https://www.sfml-dev.org/documentation/1.6/namespacesf_1_1Style.php - Style documentation (I couldn't find one for 2.5.1, but it isn't that deprecated, in new versions, there is also a Style::Deafult)
Example:
sf::Window my_Window(sf::VideoMode(640U,480U),"w",sf::Style::None)
However, you have to keep in mind, that your window won't have any border and thus won't be resizeable nor closeable until you implement this.

Can we create a graph in QLabel? If not, what's the best way to create graphs in a dialog box?

I need to create a graph in my dialog box which displays as I've shown in the image. I need some guidance to move forward with this. Example graph is shown here
So I am developing an application in Qt creator, and I need to display a graph in a dialog box that would give better understanding of different stores and comparisons among them.
Firstly I need some guidance to know what type of Qt widget should be used and then how to create those blocks as a graph.
I am not that familiar with qt grasp, can someone help me out with this?
Qt's designated widget to render images is indeed QLabel. Just render your graph, load it up on a QPixmap by calling for example QPixmap::fromImage, and then update your QLabel by calling QLabel::setPixmap.

Colorizing the titlebar in macOS with multiple colors

I have a Qt app that runs on macOS. I found a way to change the color of the titlebar here, however I want to take it a step further. I want to mimic the titlebar that the Slack and Discord apps use. For example:
As you can see, the color of the controls in the window extend to the very top of the app's window. I figure there are two ways to accomplish what I want:
I can build on the code pasted above. Looking through some of the Apple developer documentation, I think I can create a couple NsWindows on top of the titlebar with whatever width I want and attach the titlebar as a parent for those windows. Once I do that I should be able to make the same backgroundColor() color call for each one. Of course, this will require me to keep track of when the controls or window are resized and adjust the NsWindows of the titlebar, and I am not sure what (if any) issues that could cause.
Maybe there is a way to essentially set the height of the titlebar to 0? I wonder if that's what the Discord app is doing because:
if you look closely, the edit box that says "Find or start a conversation" is vertically lined with the close, minimize and maximize buttons, as is the "Activity" label. But if the controls do extend to the top of the app's window then how are the standard app buttons getting painted?
I'd be curious to know how Slack and Discord accomplish this even though I know they're not using Qt.
I realize there is not a Qt solution since Qt does not paint the titlebar. I know this will be OS-specific, but since I do not have any real experience with Objective-C++ or working with Cocoa (all of my programming experience on macOS has been standard C++ with non-UI or Qt-based code) I'd appreciate any suggestions or guidance!
Natively this is done with fullSizeContentView and titlebarAppearsTransparent properties of NSWindow. Once you set them to true, you can draw or place controls beneath the title bar.

How to create custom skin like WinAmp

I guess this question has been ask before, but I have not found sufficient answer to even start poking around. Most answer refers to catching WM_PAINT method directly and do custom rendering, or use a onwer draw object. However, I did not see a centralized place that has the info. to start researching. Hence, the question.
My goal is to create a very simple GUI program with custom look into it. I prefer the way winamp does their custom look that is customizable through "skins". However, I am not interested in using some cross-platform library like GTK+, QT or wxWidget.
I have some experience in system programming, but not much for GUI. I spent most of my time developing console applications, and I just started doing some QT development. If you can point me in the right direction, I'd be very appreciated.
PS: I am interested in both windows and linux environment.
Everybody,
Sorry for the late reply. I had a chance to have a quick talk with the original developer for winamp, and this is the quick answers I have:
Using skins: Artists create skins, developer will render the skins
To the OS (Windows), winamp is just one pretty box, nothing else. There is a container windows, and that's about it
All controls (button, label, list, etc) are implemented by winamp team themselves. All messages and stuffs are passed as relative position to the container window. WinAmp and the GUI engine has to decide if a button is clicked or if the label next to it is the target, etc.
Rendering artists skins created in XML
I do not have the details on if they use any libraries to do all that, but I am suspecting they do hook a window call directly, and do custom rendering themselves.
GUI skin usually using plug-in mechanism
I guess this is exactly what you are looking for:
https://www.linux.com/learn/tutorials/428800:weekend-project-creating-qt-interfaces-with-gimp?utm_medium=twitter&utm_source=twitterfeed
I also interested in creating custom look of window and widgets.
Speaking about widgets it's not hard, just need to create subclass (if you are using C++) or some widget and implement some methods like draw, handle etc. But this solution is good only if you use some high-level library like GTK, QT, etc. If you want to implement all controls by your own, you may get any graphics library, which can create window and do any graphics inside. For example, SDL2 + Cairo. SDL2 for creating window, Cairo for vector rendering controls/widgets. Both of this libraries are for win and linux. Another option is take opengl/vulkan + some lib for rendering window. It could be SDL2, SFML, GLFW.
If you really interested how it works on low level, then search Windows API for Windows and XLib or XCB for Linux/X.Org.
Speaking about window, I still investigate it. However I have one thought: you may create an empty window and then draw whatever you want. Then you need to add handlers for resizing window on the borders. But I am not sure if it's good solution, and if it won't freezes.

OpenCV and creating GUIs

Can I use OpenCV to create GUIs that contain buttons, list boxes, ...etc for example?
Thanks.
OpenCV has highgui built-in for making GUIs.
You can find online tutorials to get you started.
Note that this is not an extensive GUI library. You can only do basic stuff like opening windows, drawing points, anti-aliased lines, rectangles and text. There is a slider widget that can be used as a on-off button. If you need more than that, you can either
build stuff yourself (for instance drawing a rectangle with text to make your own button), or
use another library like Qt which provide plenty of widgets (buttons, menus, lists, dialogs…)
Good luck if you go for the first one!
In the Learning OpenCV, the following title is mentioned in page 101: No Buttons.
And, this is some what is mentioned under this title:
Unfortunately, HighGUI does not provide any explicit support for buttons. It is thus
common practice, among the particularly lazy, to instead use sliders with only two
positions. Another option that occurs oft en in the OpenCV samples in …/opencv/
samples/c/ is to use keyboard shortcuts instead of buttons (see, e.g., the fl oodfi ll demo in
the OpenCV source-code bundle).*
Along with the highgui functions that Simon has pointed out, others have used OpenCV in conjunction with Qt. It is possible to translate the camera frames into images on a QLabel widget, and update the image on the label periodically.
On windows, you may use cvGetWindowHandle to obtain window handle (HWND). With that handle you may call CreateWindow from WinAPI and put WinAPI controls on that window.
But you will also need to override or hook the WindowProc that was set by OpenCV for that window. Hooking and overriding explained here Multiple WndProc functions in Win32