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).
Related
In my interface, I would like to not display the dotted lines/rectangle around the currently selected item.
I read online that there was no way to do this with stylesheets, and the best way was to create a new class to override the paint method, as suggested in this link.
However, it would be great to do without having to create a whole other class.
Turns out in many cases it is possible, by simply setting QListWidget::focusPolicy to NoFocus, as suggested here.
I'm trying to create a GUI for sudoku (for improving my QT5 skills). I have decided to use for these purposes a QTableView. Up until that point there is no problem.
Now i want to draw grids to make 3x3 fields more visible. Is there any ideas, how i can do that?
I would really recommend not using a QTableView for this, it's potentially solvable by using delegates (which are mostly for data presentation) but it would be very tricky. The best solution would be for you to build a custom widget by subclassing QWidget, building the paintEvent functionality and putting a data model in place. I know that building a custom widget certainly sounds more difficult, but it's actually quite simple.
Here's some good resources to get started with:
http://www.informit.com/articles/article.aspx?p=1405227
http://zetcode.com/gui/qt4/customwidget/
http://qt.developpez.com/doc/4.7/designer-customwidgetplugin/
http://qt.developpez.com/tutoriels/braindeadbzh/customwindow/
After that the QPainter class reference will be very useful to implement your drawing commands.
I need to show my list from heap.
I am newbie in QT , so I have some questions .
1. What is better to use TreeView or TreeWidget ?
2. How can I control level of selected node ?
3. What is correct way to add items to Tree*** component ?
Thx for answers in advance ?
I came across this post that might help you decide Model-based and item-based? .
In my opinion, if you looking for a more robust and extensible program you might be better off creating your own subclassed model and setting it up with the view.
However if you just want something that you can add a few entries too and be able to link that items index up with with whatever information you want to display, then you could use the widget and add your entries to it.
As you are a beginner, I would suggest that you go the long way around and get your model and view implemented as it would provide you with more experience and will also give you a better understanding of the model view architecture; Which in the long run will allow you to develop better applications.
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.
I'm trying to display some items in a QListView with some simple text formatting changes.
My list items are dictionary entries. The word is bold. The definition is not:
the word: the definition
another word: another definition
From reading the documentation, I see I need to create a custom delegate which I started to do but I think I'm doing something wrong. Using QItemDelegate, it looks like there's an awful lot of behavior that I need to replicate for this simple modification.
Is there a way to subclass from QItemDelegate in such a way that I'm not duplicating so much code?
Edit after searching some more, I found this answer
It is recommended by the documentation to use a QStyledItemDelegate. Easier would be to use a QListWidget and to set the items to QLabels with setItemWidget and to use RichText in the QLabels.