Qt designer and draw rectangle on screen - c++

Please see the following picture:
In above picture, i specefied a rectangle, i need to draw same rectangle in my program with Qt-Designer, But i don't know to use what widget.
Can i use qt designer or i should just use code?
Notes: I attemp to use QLabel and put --- and | but they don't stick.
My question is , Which widget can help me?

The box that you have circled in the image is a QGroupBox, and can be created using the QtDesigner. Other widgets can then be inserted into like any other widget that supports layouts.

Related

How do I create a "hole" in my Qt window?

I would like to create a "hole" in my QMainWindow.
Suppose the black rectangle is the "hole" of a QMainWindow. Inside the rectangle should be anything behind the QMainWindow. For example, if the QMainWindow is opened on top of my desktop, then inside the rectangle should be part of my desktop background image.
Is there any solution to achieve this?
You should use QWidget::setMask or QWindow::setMask. There is a Qt Example for that: https://doc.qt.io/qt-5/qtwidgets-widgets-shapedclock-example.html

Qt pushbutton palette

I'm using GUI form editor in qt creator, I have set the background
(right_click -> change_stylesheet->Add Resource -> background_image)
Then I added a few buttons, the buttons are colored like the background, instead of being normal - default. I was trying this with properties->palette but with poor results. I'm new to qt, so I am asking for your help.
Like in CSS, Qt Style Sheet will apply your styling rules to any item that matches them.
If you just write:
background-image: url(:/my_background.png);
it will change the background of all the widgets in your application.
If you want to change the background of the main window only, you should write:
QMainWindow {
background-image: url(:/my_background.png);
}
That will apply the background image only to the QMainWindow object.
For an detailed explanation of Qt Style Sheet, I invite you to read the official documentation here.

How to activate centralWidget in QT Designer

I was looking at this article
How to make a Qt Widget grow with the window size?
but when i got to the answer I got stuck on "activating" the central widget. I notice an icon with a red circle so I guess that means its disabled. I've been searching the net to try to figure out how to "activate" it but I am not having any luck.
Can someone please help me out?
Have a look at the layout system.
That icon does not mean your QWidget is disabled, that just mean you do not apply a layout on it.
Try to press like Ctrl+1 in order to apply a basic layout. If nothing has changed, you might need to put a QWidget inside the central widget first and then apply the layout.

QT window within window?

I'm setting up a small code editor using QT and following this example. However, i'm curious on how to create windows within windows or widgets within widgets. I'm trying to achieve something similar to these:
http://i.stack.imgur.com/Vn8Ut.png
http://www.hanselman.com/blog/content/binary/Windows-Live-Writer/Download-Visual-Studio-2013-while-your-f_1431E/image_4eb5427c-1ae7-4464-9c26-2282fe8d06c3.png
Is there an example of overlaying widgets like this?
Any alternative soloution for QMessagebox for IOS development (QWidget application only)?
I gave an example of getting another QWidget to be embedded and painted on top of another one. Let me know if you have any questions about how it was done.
The PopUp flag and Qt::Tool options are also relevant.
Be sure to check out: the ToolTip property of a QWidget and the WhatsThis property of QWidget.
http://qt-project.org/doc/qt-5/qwidget.html#toolTip-prop
http://qt-project.org/doc/qt-5/qwidget.html#whatsThis-prop
There are also other ways to make borderless, focusless windows that hover and disappear quickly on command. The Window Flags and Widget Attributes in Qt are very powerful when you are looking to modify Qt Widgets.
When you parent a Widget to another widget, it will draw itself on top of the other. Then you just need to resize and position it properly.
Also subclassing existing widgets can give you more options.
Draw text on scrollbar
Also common Qt::Tools that you will find are QDockWidgets. They are awesome!
Hope that helps.
Take a look at Qt Namespace especially Qt::WA_LayoutOnEntireRect and Qt::WA_StyleSheet. Pass it as a widget attrybutes. The second option looks promising but you have to create style sheet for QWidget.

Best way to draw simple rectangle in Qt

I am writing a little program in C++ with Qt.
I have a QGridLayout with 3*3 QWidget. In each QWidget, I have a QVBoxLayout.
Within that QVBoxLayout I need to put a certain number of black and white rectangles.
For now, I use QWidgets for these rectangle and I apply a background-color to get the white and the black ones.
I saw in the documentation something about a Rectangle class that is linked with QtQuick and I don't really want to go into that.
Thanks for your answers,
I wouldn't bother with the layout and widgets unless you actually need interactive objects for each square. Just overload the paintEvent member of the widget you are using that contains the grid layout and use the QPainter object and call fillRect.
To get an outline around a widget, use a QFrame. Also QLabel subclasses QFrame. There are a lot of examples of using QFrame in the documentation.
Hope that helps.