How to include a QPushButton into popup created by QCompleter?
I would use QFrame with a Listbox or QTableView and QPushButton included. But method void QCompleter::setPopup(QAbstractItemView *popup) requires QAbstractItemView (not QWidget).
What is desired:
I never used a QCompleter, but all visual items in Qt are derived from QWidget.
If you check the doc for QAbstractItemView you see it is derived from QAbstractScrollArea -> QFrame -> QWidget, so it is a QWidget after all, but you have to use specialized form. The QAbstractItemView has some child classes you can use, like QListView or QColumnView. Check the Qt doc for more info: http://doc.qt.io/qt-5.8/qabstractitemview.html
Related
I have setup my app to have various dock windows within the main window. I am also able to add a toolbar to the main window. However, I would ideally like to add the QToolBar inside one of the QDockWindow instances (or the QWidget that it houses) as the toolbar will be specific to that window.
Is this possible? I'm using a recent version of Qt, 5.10.
I think it is possible.
1.QDockWidget can set a QMainWindow by setWidget() method.
QMainWindow is made for just a mainwindow but it is not prevented from being used as a subwidget.
2.QToolBar can be attached to the main-subwindow by addToolBar() method.
3.The subwidget-mainwindow can naturally have its own QToolbar.
If you don't want to use QMainWindow as the widget of its QDockWidget,you can attach the QToolBar as a child widget of QDockWidget. But The toolbar is not movable as QMainWindow's.
I think you want to add QToolBar and use it as QMainWindow.
So I recommend that you set a QMainWindow as the widget of QDockWidget.And you attach any widget you like to the mainwindow after that.
Completely using QT Designer. I've created a QWidget to encapsulate a collection of controls. I now want to use this QWidget several times in the QMainWindow form.
How do I 'put' my QWidget onto the QMainWindow using QT Designer only?
Shouldn't this just be a simple drag and drop operation? What am I missing?
You can promote widgets.
Simply drag and drop QWidget into your mainwindow with QtDesigner.
Right click on it and press promote to In the dialog fill in your created widget's Class name (header should be filled in automatically if it doesn't match edit accordingly) press add and promote.
Now build and run your application and you should see your widget with collection of controls.
How can I paint on a widget without overwriting the paintEvent.
I want to paint on a widget which is inside another one generated by Qt Designer , so i can't overwrite its paintEvent.
I tried to paint directly like this :
QPainter *painter= new QPainter(ui->drawArea);
painter.drawLine(50,50,50,150);
painter.close();
but Qt tell me that the QPainDevice is 0 or something like this,
I tried the same example by creating the painter then call the begin() method with the QPaintDevice (the widget) but same problem.
Qt version : 4.8.6.
Using custom widgets in Designer is not an issue. In Designer, add your widget as any other QWidget or QPushButton, depending which has the closest inheritance. Then with right click menu select Promote to ..., add your MyWidget.h and then promote the widget to MyWidget with reimplemented paintEvent(). Read more:
http://doc-snapshots.qt.io/4.8/designer-using-custom-widgets.html#promoting-widgets
In the QObject.__init__(self, Parent=None) documentation it states:
The parent argument, if not None, causes self to be owned by Qt instead of PyQt.
What does it mean to be owned by Qt instead of PyQt? Does this have effects on behavior that I should be aware of when developing a PyQt application?
Yes, It is. It have Effects to before create any object in PyQt application. If we set parent QWidget None, I can be tell this QWidget is top-level window. I will try explain;
"Parent Widget equivalent like frame of windows"
Parent Widget of QMainWindow is none. Then, owned by Qt instead of PyQt (or easy word root). Parent Widget of QWidget (in red) is QMainWindow, Then geometry reference by QMainWindow. Parent Widget of QPushButton is QWidget (Green), Then geometry reference by QWidget (Green). And all widget as same ...
So, QMainWindow have fully control widget in your child. For example, If self delete, All child will follow delete too. etc.
But, If we set Parent Widget of QWidget (in red) is None, that mean this QWidget like new window. Like this picture;
For now, we have 2 top-level window. But QWidget have independent with QMainWindow. If self delete, All child will follow delete too but not outside QMainWindow. Outside QWidget not delete. So, some application have create many widget, but it will has main widget in main menu to control child.
Not only frame of windows, It just Example & Comparison.
Regards,
I have a QWidget container that contains my custom widget. This QWidget container was promoted to the custom widget I created. I have a QPushButton on my MainWindow.ui. I want to connect this QPushButton to the promoted QWidget. How will I do this?
For example, I have a function on my promoted QWidget class, and I want to call this function when I click the QPushButton located at the MainWindow.ui.
Thanks in advance!
Have you considered using a connect??
connect the QPushButton singal clicked to that function (make sure its a slot where its declared).