How to deal with QPushButton in a item of a QListview
-
For how to use the QPushButton you can have look here : "Class QPushButton":http://doc.qt.nokia.com/latest/qpushbutton.html
About how the QPushButton emit signal : "Use QObject":http://wiki.forum.nokia.com/index.php/How_to_use_QPushButton_in_Qt
-
[quote author="Milot Shala" date="1293453592"]I think you should avoid using QListView on mobile screens because QListView is not made for mobile screens, it's rather a Desktop widget.
What you can do is use QScrollArea and use custom made widgets inside it, use a QVBoxLayout to place them vertically.[/quote]
Oh,no,I have implement the itemDelegates in my listview, but I could only draw the string and the buttons on the items, how to bind the signals to the button is not achieved. It is a little difficult for me.
Milot Shala, would you give me an example or a code snippet about how to use use QScrollArea and use custom made widgets inside it?
-
[quote author="qtrahul" date="1293455183"]For how to use the QPushButton you can have look here : "Class QPushButton":http://doc.qt.nokia.com/latest/qpushbutton.html
About how the QPushButton emit signal : "Use QObject":http://wiki.forum.nokia.com/index.php/How_to_use_QPushButton_in_Qt[/quote]
Thanks, I know how to emit a signal with a custom widget and how to use the QPushButton.
But in the listview, I don't know how to "create" buttons and use them. -
You have to add the buttons yourself. It's usually done in the class that contains the list view. As you use a list view you will also have a model. Connect to the columnsInserted and rowsInserted signals to catch changes in the model and add the buttons for the new data in the view. Also signals columnsAboutToBeRemoved and rowsAboutToBeRemoved should be connected in order to remove the index widgets before the model deletes the rows/columns.
-
[quote author="hisong1988" date="1293455342"]
[quote author="Milot Shala" date="1293453592"]I think you should avoid using QListView on mobile screens because QListView is not made for mobile screens, it's rather a Desktop widget.What you can do is use QScrollArea and use custom made widgets inside it, use a QVBoxLayout to place them vertically.[/quote]
Oh,no,I have implement the itemDelegates in my listview, but I could only draw the string and the buttons on the items, how to bind the signals to the button is not achieved. It is a little difficult for me.
Milot Shala, would you give me an example or a code snippet about how to use use QScrollArea and use custom made widgets inside it?[/quote]
Think about event filters and installing them on the viewport. A colleague of mine implemented kinetic scrolling feature using the technique I just mentioned, maybe his idea will help you.
"Here's the idea and the implementation":http://wiki.forum.nokia.com/index.php/Qt_Kinetic_scrolling_-_from_idea_to_implementation
-
[quote author="Milot Shala" date="1293466891"]
Think about event filters and installing them on the viewport. A colleague of mine implemented kinetic scrolling feature using the technique I just mentioned, maybe his idea will help you.
"Here's the idea and the implementation":http://wiki.forum.nokia.com/index.php/Qt_Kinetic_scrolling_-_from_idea_to_implementation[/quote]
I think I should test the QItemDelegate first, but how to use the filters? I noted that there are two methods of QItemDelegate:
@
virtual bool editorEvent ( QEvent * event, QAbstractItemModel * model, const QStyleOptionViewItem & option, const QModelIndex & index )
virtual bool eventFilter ( QObject * editor, QEvent * event )
@
Does it mean that I should implement both of them?
and how to "catch" the event that the buttons I painted? -
p.s. My buttons only deal with the parameter QModelIndex & index, and each button of the item would be the same appearance and location. But the strings was depended by the model
-
[quote author="hisong1988" date="1293504838"][quote author="Milot Shala" date="1293466891"]
Think about event filters and installing them on the viewport. A colleague of mine implemented kinetic scrolling feature using the technique I just mentioned, maybe his idea will help you.
"Here's the idea and the implementation":http://wiki.forum.nokia.com/index.php/Qt_Kinetic_scrolling_-_from_idea_to_implementation[/quote]
I think I should test the QItemDelegate first, but how to use the filters? I noted that there are two methods of QItemDelegate:
@
virtual bool editorEvent ( QEvent * event, QAbstractItemModel * model, const QStyleOptionViewItem & option, const QModelIndex & index )
virtual bool eventFilter ( QObject * editor, QEvent * event )
@
Does it mean that I should implement both of them?
and how to "catch" the event that the buttons I painted?[/quote]
No you should implement only the eventFilter then use installEventFilter(QObject*) on a widget. Please read "this":http://doc.trolltech.com/4.7/eventsandfilters.html part of the docs.
-
If you go for the item delegates, I'd strongly recommend sublcassing "QStyledItemDelegate":http://doc.qt.nokia.com/stable/qstyleditemdelegate.html as it is the default used by Qt itself.