Sortable QBoxLayout - qt

I have a list of QGroupBoxes and I want them to be "sortable" as in drag and drop to another order. Very much like QListView does it with InternalMove.
Is it possible to do this without reinventing the wheel one more time?
I do know I could do it myself with drag and drop, but with nice position indicators while dragging etc it's not something one without much qt experience can finish in just a few hours. I've already looked at how QListView does it but it seems to implement it completely from scratch, or is there an easy way for me to use any of it?
Another idea I had was to actually use a QListView but it doesn't seem to be that simple to put QGroupBoxes in there. I tried subclassing QStyledItemDelegate and while painting works quite fine I have trouble with the editor - I guess I would ideally return a copy of my groupbox in createEditor? But it's been two hours since I had the idea and it's far from working.
btw, this is not a duplicate of Sortable QHBoxLayout - completly different issue

Related

How to merge two QGraphicsItems into a custom one?

I have a problem that I don't know how to face and I was looking for some help. I recently started using Qt and I do not really know how Qgraphicsitems works.
I have a scene and I have to create a group of graphics items everytime my program starts, but sometimes I have to update some of those items that are always together.
So I was thinking about creating one Qgraphicsitem with all of them in it. That way i can handle them easily. My problem is that I'm not sure if that is a good approach. In a modular point of view it make sense because that group of items are always toguether and that way I do not have to create all of them everytime, but I do not know how to do it in the first plane how can I create a QgraphicsItem that has some QgraphicsItems in it?
Sounds like you're looking for QGraphicsItemGroup:
The QGraphicsItemGroup class provides a container that treats a group of items as a single item.
https://doc.qt.io/qt-5/qgraphicsitemgroup.html

Displaying QML Item over a QWidget

I want to make an application that will benefit both from OpenGL and QML advantages. I want to use QOpenGLWidget and place QML Item over it. Item will be partially transparent. I though it may be possible by using QQuickView but I just figured out that it does cover all transparent parts with black color. An attempt to achieve what I need (an example project) may be found on my GitHub here.
Is it possible to render QML Item with all children onto an existing QWidget in such way that it is visible under Item, wherever Item is not completely opaque?
I guess that in the worst case scenario I could create bitmaps from the QWidget and the Item objects, somehow combine and display them but I seek easier way. If there is no easier way I could just never display those two at the same time.
The reason why I do not want to use OpenGL features in QML directly is this. Maybe I should just use the work around mentioned in the link.
I think you don't need Widgets for it. You can do custom rendering in QtQuick using QQuickFramebufferObject class. I used to do it before, though don't have code anymore. This article seems to explain what to do https://blog.qt.io/blog/2015/05/11/integrating-custom-opengl-rendering-with-qt-quick-via-qquickframebufferobject/

Qtablewidget or Qtableview, which is more proper to make a downloading task list?

Qtablewidget or Qtableview, which is more proper to make a downloading task list ?
I want to make a downloading task list like this
http://qt-project.org/doc/qt-4.8/images/widgetdelegate.png
the first question is : Qtablewidget or Qtableview, which is more suitable for this job ?
the second question is : how to draw a progress bar in the downloading task list ?
P.S. if chosing Qtablewidget ,I know it has a
QTableWidget.setCellWidget(row, column, widget)
method ,so we can use it to set QprogressBar there .
if chosing Qtableview, we can use Delegate like here
http://qt-project.org/doc/qt-4.8/qabstractitemdelegate.html
(maybe QStyleOptionProgressBarV2 will be more appropriate for the current Qt )
the same question comes here again :which way is more appropriate to do this ?
can anyone give a little example ? cuz the the Qt Torrent Example is so complicated for a newbie like me to learn from it .thanks !!!
Up to me it's very interesting discussion topic. If you look carefully in the documentation you will see that QTableWidget is actually a QTableView with specialised table-oriented functions, default table model, support for widgets in cells out of the box etc. It still has everything which QTableView has if you need some low level customisation. So you really don't have to choose. If you think (and looking on screenshots examples I would agree with that) that QTableWidget can handle most of things you need (like progress bars etc) just take it and go ahead with setCellWidget(...). Since it's QTableView anyway you always have an option to substitute it with your own QTableView implementation with fancy delegates etc.
I think in your scenario you you will use very limited amount of QTableWidget specialised functions, so that shouldn't be any problems at all.
Making it short, on your place I would go for QTableWidget.

Rendering a custom select list in Qt

I'm a really confused by the different options of drawing in QT. To make it clear, I'm not asking for code. Just I'd be so thankful if someone can shed a light on the best way to implement that. I don't think it's very complicated!
Here is the result that i'm looking for!
The main idea is to have a textinput at the top and a list of suggestion above with matched results.
At the moment, I use a QTreeWidget, and add rows with a QTreeWidgetItem with a QStringList. Obviously it doesn't look like the screenshot :) Should i use a QItemDelegate to handle the drawing? I did some research, but it looks a bit painfull to draw with a QPainter. I thought it would be easier to implement a custom widget and replicate it somehow with maybe a QListView? QListWidget?
Thanks.
You could indeed try to use a QListView to draw your combo, it might be a tad simpler to handle than a QTreeWidget.
Unfortunately, I'm afraid you will have to subclass a QItemDelegate (or some other kind of delegate) to handle a custom display of your data (eg, mixing an icon, a few strings and a date field...).
For the data itself, you may want to consider using a QStandardItemModel. Because you only want to display some data, overwriting the data method should be enough (along the rowCount and columCount methods, of course).

Custom action plugin for Qt Designer

I plan to use a spacer in my toolbar (below) between the 'Pause' and 'Settings' buttons to make the 'Settings' button right-aligned within the QToolBar. The separator below isn't cutting it.
The following method apparently works, although I haven't actually tried it yet:
QWidget* spacer = new QWidget();
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
// toolBar is a pointer to an existing toolbar
toolBar->addWidget(spacer);
toolBar->addAction("Right-aligned button");
(thanks to http://www.ffuts.org/blog/right-aligning-a-button-in-a-qtoolbar/)
Qt Designer doesn't seem to allow adding widgets to a QToolBar, although QToolBar does have an addWidget() method, as used above. So if I want to be able to add the spacer to my toolbar using Qt Designer (with a plugin, not promotion), should I subclass QAction, QWidget, or QWidgetAction? Is there even a way to write custom action plugins for Qt Designer?
You cannot subclass QAction and expect to use it gracefully in Qt Creator/Designer. It uses the tags in the ui and to add them to menus and toolbars. You can't specify a class="customclass" element along with a entry like other widgets. Because actions are treated differently, you cant even subclass them so that's out.
As for QWidgetAction/QWidget, you are in the same boat as QActionGroup, if you know what I mean.
(I personally think this is a big overlook in the design of the form designer!) So previewing that in the designer is also out.
The last thing you could do (invisible option 3) is QToolbar subclassing, but alas you can subclass it, but still, you wont be seeing anything in the desinger other than what a plain old QToolbar can do. That doesnt mean that it is completely out which is the point I'm coming to:
The real answer would have to be invisible option 4, subclassing QToolbar as a designer plugin (which would require a lot of coding on your part if you dont already know of one that is out there, I dont know of any that actually have designer plug-ins) Form Designer plugins are more not than often, but you could find someone's subclassed toolbar, and make it into a plugin yourself saving you a step (qt creator even has a template for that), then use it in qt designer and your set.
I know this question got asked 2 years ago but when I see an unanswered question, I think of those searchers that might read and get frustrated by a dead-end so if I can contribute I do... I hope I did at least help you or anyone else get on the right track, and good luck to you all!

Resources