Attach QDockWidget to QWidget - qt

I don't understand from the documentation (http://doc.qt.io/qt-5/qtwidgets-mainwindows-dockwidgets-example.html) whether a QDockWidget can be attached to a QWidget.
I m trying to create a new additional window (a QWidget) and I would like to attach to it a Dock, but when I pass the QWidget as a parent, the Dock shows up in the QMainWindow

Related

Can't move items in qgraphicsscene

I'm trying to add items to qgraphicsscene, and move them later. I am using QMainWindow and QFrames to organize content of window and I can add items, but can't move the items. In tutorials I have found authors use QDialog and QgraphicsView as the only widget. Is that what makes the difference ? QMainWindow does not pass mouse events to GraphicsView or QGraphicsScene ? Any help appreciated.
def _add_area(self):
item = QGraphicsRectItem(0, 0, 100, 100)
brush = QBrush()
brush.setStyle(Qt.Dense7Pattern)
brush.setColor(Qt.darkBlue)
item.setBrush(brush)
item.setFlag(QGraphicsItem.ItemIsMovable)
item.setFlag(QGraphicsItem.ItemIsSelectable)
self._scene.addItem(item)
Ok, it seems I've found solution. When I removed QGraphicsView from QFrame it started working ( now QWidget is the parent of graphicsview ).

How to remove the focus of a QGraphicsTextItem from a main QWidget

I have a number of QGraphicsTextItem and QGraphicsItem painted inside a QGraphicsView. This QGraphicsView has been added to the main Qwidget.
I have written the "FocusOutEvent" for this QGraphicsTextItem and the focus is getting removed only when the "MousePressEvent" is called within the QGraphicsView.
Now my concern here is, How to remove the focus of this QGraphicsTextItem when the MousePressEvent is called Outside the QGraphicsView?
In my MainWindow.cpp, I wrote a mousePressEvent function :
void EyGuiMainWindow::mousePressEvent(QMouseEvent *e)
{
QWidget *w = QApplication::focusWidget();
if(w)
w->clearFocus();
}
But this is not clearing the QGraphicsTextItem.
Expecting a positive response.
A QGraphicsTextItem is not a widget, but a QGraphicsItem. Graphics items are added to a QGraphicsScene and viewed by one or more QGraphicsView widgets.
The code presented is only calling clear focus on the currently focussed widget, but since the QGraphicsTextItem is not a widget, it won't be cleared.
In order to clear the focus on the QGraphicsTextItem, call its clearFocus function. If you don't have a pointer to the item, you can get a list of all the items in the scene with the items() function and iterate through them.

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 to add menu to a widget derived from Qwidget

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.

Resources