Reputation: 61
I'm trying to write a tool in C++ that will help me with my language study. It will capture an area on the screen (a word or sentence), process the text, then display information on the captured text in a GUI application.
This is a basic diagram of what I'm trying to do:
This is supposed to be very similar to screen capture tools like gnome-screenshot and Microsoft's snipping tool on Windows.
A third party application is something like a pdf viewer or image viewer that contains scan-able text. My application displays information about the captured text. My application also draws a resizable 'capture window' on the screen, shown by the red box that surrounds a word in the diagram.
My question is about drawing this red box on the screen. How can I draw a red box on the screen? I've been trying to do this with both xLib and QT, though I would prefer to do it with QT since it's better documented and cross-platform.
edit: I modified the question to make it more concise and clear to my objective, and how the accepted answer solves my issue.
Upvotes: 0
Views: 308
Reputation: 61
The accepted answer is the preferred solution to this question, but after answering this question I found an example project that accomplished what I was going for using xlib.
https://github.com/gvalkov/xrectsel
I included this for completeness, but the QT solution has better API and is cross-platform. So, this better suits my needs for this program.
Upvotes: 1
Reputation: 618
You need to create a frameless, alwaysOnTop window that contains a widget. The window should be defined as having a translucent background, whereas the widget will be used to display the border (or semi-opaque background). You can then manipulate the position and size of the window through code by detecting mouse clicks on your window that opens the pdf.
Here's an example:
The code:
QMainWindow window;
window.setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
window.setAttribute(Qt::WA_TranslucentBackground, true);
window.setFixedSize(80, 20);
window.move(500,500);
QWidget widget(&window);
widget.setStyleSheet("border: 3px solid rgb(255,0,0)");
window.setCentralWidget(&widget);
window.show();
Upvotes: 1