I have some information/notification widget that should be displayed when some even occurs. My idea was to have a widget that is hidden in top left corner and would be shown when needed. Problem is that if I just put there simple widget and show it, everything will be moved to the right, what I want is to show that widget on top anything that's in that area (it will hide what's there, but that's ok). I can't use stacked widget, because information widget is in different dimensions then other widgets there. And if I just create floating widget and move it to that area it wont move if main window is moved. Is there any way how to do that?
Qt widget displayed over other widgets
Asked Answered
Set a parent to the widget but don't add it to a layout. Would that work? –
Deina
Just create and place the widget on the fly. Avoid using UI to place the widget because then the widget position is managed by the layouts.
EDIT: Remember to create the widget after of the dialog's initialization. If you don't take care about this your widget will be inserted at the bottom.
class Dialog : public QDialog
{
Q_OBJECT
std::unique_ptr<Ui::Dialog> _ui;
QWidget* _widgetOnTheTop;
public:
Dialog(QWidget* parent)
: QDialog(parent), _ui(new Ui::Dialog)
{
_ui->setupUi(this);
_widgetOnTheTop = new QPushButton(this);
_widgetOnTheTop->setGeometry(10,10,100,35);
_widgetOnTheTop->show();
}
};
Look at QDialog
create and exec one of them when your error occurs, you can construct them to have the default ok cancel buttons
EDIT: Sorry i mean QMessageBos, see code below
QMessageBox error_message(QMessageBox::Icon::Critical, "Title of the window","Some Text about the error to show the user", QMessageBox::StandardButtons(QMessageBox::Yes | QMessageBox::Cancel), this);
error_message.exec();
It's not error, it's some additional information about object they triggered by some action, for example rotation angle to some axies. Therefore I can't use modal dialog (and prefer not to use detached from main widget). Information in that widget might be useful for user at that moment (or until some other action), or might not (in that case he will just close/hide). –
Tuscan
If you are using visual studio, you can see something similar if you have toolbox on right (or left side) with auto hide feature. It will go over existing layout, but not affect it. –
Tuscan
you could use a QDialog then just create it and then set flags for non modal and always on top, just seems a better way to do it than to add another hidden widget and show it when needed... –
Bernardina
can you use tooltip? if not, maybe you can use stackedwidget, but that requires some programming. –
Chadwell
Tooltip wont allow interaction, at least afaik, and stacked widget requires that all widgets in that place are same geometry and they are different. –
Tuscan
© 2022 - 2024 — McMap. All rights reserved.