How to add menu to a widget derived from Qwidget - qt

i want to know how to add menu to a widget, which is derived from Qwidget in QT symbian,
i know how to add menu to window derived from Qwindow, but i am not getting for widget
derived from Qwidget
pls help me..
Thanks

QMainWindow provides you convenience function to add and manage a QMenuBar.
With a window that inherits from QWidget (instead of QMainWindow) you need to achieve this by yourself. You can add the menu bar in the window layout like any other QWidget using the function add. By playing with the layouts you can place QMenuBar at the top of the window.
An other way can be to use a QToolBar.

Related

pySide/ pyQt - Marker bar?

What would be the easiest way to create a marker bar in PySide/ PyQt, similar to
(source: sideofsoftware.com)
?
There is a QScrollBar class. You can subclass it and override the paintEvent method to do custom painting. Any class that inherits from QAbstractScrollArea (e.g. QScrollArea, QTextEdit, etc.) has two methods to set the scrollbar for the vertical or horizontal scrollbar (e.g. setVerticalScrollbar()). So create your own scrollbar class and then use those methods to apply it to the widgets that can use it.

Qt widget displayed over other widgets

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?
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();

QDockWidget is not docked on a QDialog

Is it correct to use a QDockWidget on a QDialog? When I tried to use it, dock widget did not get docked on the dialog window. I could not resize the dock widget when I executed the application.
QDockWidgets have to be 'owned' by a QMainWindow, but you can of course put a QMainWindow inside a QDialog.

Qt : event invisible widget?

For some reasons, I need to draw a widget onto one another.
The structure is the following (see the image) :
I have an original QTableWigetItem
On the QTableWigetItem, I create a QWidget at the foreground with the same geometry
This QWidget contains a QBoxLayout
This QBoxLayout contains a QPixmap and a QComboBox
I want to do the following things :
The QWidget is just a "container" for my QBoxLayout and I would like to set him completely "invisible" for the user. If the user click or move at the position of the widget, I want the event of the QTableWigetItem in the background to be trigerred. But the problem is that I want the QPixmap and the QComboBox to be at the foreground, visible and "normal". For me it's just a trick to be able to put children widgets in a QTableWidget of a HeaderView.
How to make the QWidget "completely invisible" (from the event/signals point of view) ?
Thank you very much.
Try QWidget::setWindowOpacity(0)

How does QWidget size when used as a window?

Several examples on trolltech use QWidget rather than a QMainWindow as the main window for simple Qt applications.
Now I need just a simple window with a single content widget (QGlWidget) that covers the entire client area.
However, when I show a QWidget window with a single content window it automatically resizes itself to be tiny.
If I create the QWidget parent window without a child It is a nice large default size.
I don't want to resort to using Layouts for a single child window :/
What I understand is that you use a QWidget to display your QGIWidget. Try calling the show method of your QGIWidget directly (if your QGIWidget class inherits QWidget), Qt will create the window decoration for you.
Otherwise if you really need your widget to be inside one another, and fit its size, you'll have to use a layout.
Either follow gregseth's advice or you can simply resize the widget yourself.
(though this way you'll loose nice auto-resizing which is provided by Qt when you use layouts)
In your case you can basically do something like:
QGlWidget* myWidget = new QGlWidget;
myWidget->resize(QApplication::desktopWidget()->availableGeometry().size());
// or maybe instead of resizing show it in fullscreen:
myWidget->showFullScreen();
(actually I don't remember if showFullScreen() will do resizing for you, maybe you'll need both resize+showFullScreen :))
Cheers :)
P.S. Using layout is actually an option. It's not expensive and it's flexible. All it gets: "layout = new QVBoxLayout(myWidget); layout->addWidget(myWidget);" and you're done :)
Not always.
I've found that a QMainWindow will not work as the parent widget when using the QVBoxLayout and QHBoxLayout to arrange child widgets.
If you create a QWidget and use that in place of the QMainWindow then the layouts will work correctly.
QWidget* centralWidget = new QWidget( MainWindow );
MainWindow->setCentralWidget( centralWidget );
If you use QtCreator and look at the code it creates you can see it creating a 'hidden' widget if you try to use the layouts directly at the top level.
It's not obvious, intuitive, or documented anywhere that I've found.

Resources