How to make the position of Widget fix? - c++

I am creating a widget on click the button. The widget is appearing at center of the screen. I want to show that widget at a proper predefined position of the screen. And when ever I open that widget it should show at that point only. How to do this not able to understand.

Use QWidget::move() function before you show it.

Related

Is there a way to attach or anchor two QWidgets together?

I'm getting started with Qt and decided to build a full-screen text editor. I want to have a button (button with arrow in screenshot) attached to a QDockWidget which opens and closes it so the button is always visible to the right side of the screen and stay anchored to it when dock is visible or resized.
My current app is a simple fullscreen textEdit set to centeralwidget in Mainwindow.
I haven't found a way to do this yet with layouts or existing addAnchor() functions so any help or direction is appreciated.
You can achieve what you want by using a container for your text edit and the button. A QWidget instance can be used as an "invisible"*** container for other widgets.
So in Qt Designer you add a widget as a central widget of the main-window, inside this widget you add the text edit and the button, then you set a vertical layout for this container widget.
Don't forget to restrict the docking widget to only dock to the right side, you can do that with: dock->setAllowedAreas(Qt::DockWidgetArea::RightDockWidgetArea); //assuming dock is the pointer to your QDockWidget.
In case you want the dockWidget to be able to dock to any side and the button to follow, you can do that too, but it get a little bit more complicated. Basically you need to connect a slot to dockLocationChanged of your dockWidget and based on where it's docked you need to set-up a new layout for the container widget to be vertical or horizontal and the order of the textEdit and the button based on the side the dock happened.
LE:*** you will most likely need to set the margins you want, since both the widget and it's layout can have them and the actual content might have higher spacing than you want.

Display image thumbnails with closing button in Qt

I have a widget that should display images that user has chosen (something like they are shown on the screenshot) and I need to allow users to remove images from this widget. Is there already some widget capable of doing this in Qt or I need to implement such widget by myself?
So, basically I need to display a small image with small closing button in top-right corner.
Yeah, you can. Make a custom widget

How to add a widget to a qt Tool bar

I have the following problem:
I have added a spinner to my qt Tool Bar, which is located from top to buttom. This works fine. But now I want to order some buttons in a special order, but with mainToolBar->addWidget(button_name) it would be among one other. So how can I solve it? I tried to make a new widget "widget_1" and added some buttons to this widget, but when I write mainToolBar->addWidget(widget_1) nothing appears, only the one slider I have already added. Can anyone help me?
Thanks a lot :)
Well, just forget something.
select the widget and then layout in a form or whatever layouting you prefer.
And that's it. now, the widget will be shown in toolbar. it's because of size
and child widgets position. by layouting, everything will be resized and position
correctly.

How to Bring the Widget Bring to front in Qt?

Please have a look at this screenshot:
The circles are custom controls. When I click a control, I need to bring the widget to the front. Ex. if I click the second circle it should look like this:
When the control is clicked I am able to get the sender (i.e. the control). Only thing is how to bring the object to the front.
Please help me fix this issue.
Have you tried QWidget::raise()?
Raises this widget to the top of the parent widget's stack. After this call the widget will be visually in front of any overlapping sibling widgets.
Note: When using activateWindow(), you can call this function to ensure that the window is stacked on top.
So the pattern I usually use that will ensure a window is shown, brought to the front of sibling widgets and brought in front of other applications is:
widget->show();
widget->activateWindow();
widget->raise();

Qt: Dragging a widget to scroll the widget's parent QScrollArea?

I've got a long horizontal QLabel displaying a png (the image shows a signal/time graph). Under that, I've got a QTableWidget. Both of these are in a QScrollArea because I want them to stay vertically aligned (the cells in the table correspond with the signal seen directly above them). I'm trying to add a handler to the QLabel such that the user can use the picture itself to scroll the scrollarea, rather than having to use the scrollbar. Is there a tried-and-tested way to do this? Directly setting the scrollarea's sliderPosition inside the QLabel's dragMoveEvent doesn't seem smart, because when the scrollarea scrolls it also leads to another dragMoveEvent on the (moving) QLabel.
I would suggest wrapping the combination (including the scroll area) in their own widget, and overriding the dragMoveEvent() on that widget. The dragMoveEvent() shouldn't be triggered when you change the scroll position if you are doing it this way, I wouldn't think, although I haven't actually tested it.