PDA

View Full Version : QTableWidget + setCellWidget facing problem.



danish.ahmed
25th August 2010, 06:38
Hi,

I am new to Qt programming and i want to add the functionality in QTableWidget. Whenever a user clicks on to any cell in QTableWidget, it should display QLineEdit and QComboBox in QHBoxLayout. And i am facing problem in doing that, can anyone help me out. As how can i do it using setCellWidget??

Lykurg
25th August 2010, 07:01
Therefore you have to create your own delegate and provide a custom editor. See in the docs about custom delegate in the model view framework. If you struggle with it, ask again.

danish.ahmed
30th August 2010, 07:08
Hi Lykurg,

Thanks for replying, but i just wanted to ask u that, can't i do this using setCellWidget??? Actually i am facing problem in understanding the whole flow of M/V programming :(
could you help me with some examples???

wysota
30th August 2010, 10:16
Thanks for replying, but i just wanted to ask u that, can't i do this using setCellWidget???
You could but it's like eating soup with a fork. Do it the proper way - with a delegate.

weeezes
30th August 2010, 17:31
There's the Star Delegate and the Spinbox Delegate examples in the Item View examples, those were pretty easy to understand :).

danish.ahmed
23rd September 2010, 07:26
You could but it's like eating soup with a fork. Do it the proper way - with a delegate.

Thanks wysota,

But i still have some doubts like should i create a new class to handle QTableWidgetItem and then create a delegate(create_editor???) through which we can customize our cell or should i just create a create_editor( ) of type QWidget and use it in setcellWidget(i, j, QWidget) in the current QTableWidget class???? I am confused, what to do??
And i know its kind of hard to understand what i am trying to say here, if u want, then i can upload the code here, i have the whole flow going but i just need to add a QTextedit and QComboBox in each cell when clicked.... please help me out :)

Thanks!!!

wysota
23rd September 2010, 08:12
Read about QAbstractItemDelegate and its descendants.

prin
7th October 2010, 06:06
Hey guys,

Even i'm stuck with the same kinda problem, i have one question, i also want to customize the cell of a Tablewidget, i have tried all the things but m nt able to go one step further, just wanted to know for customizing my cells in tablewidget which is working fine, do i need to create a new class for handling items and customize them. And right now m using tablewidgetname->item(i,j)->setText(variable) to insert value in the tablewidget. if i m going to built a new class of type QTableWidgetItem, which handles each item, what do i do in constructor of dis class?? n how do i customize it. i have seen each and every example but m not getting any further. can nyone explain, what should b done and how.....

N sorry for bad english..... :D

wysota
7th October 2010, 11:33
Please edit your post and write it in simpler, shorter sentences with more or less proper English grammar without skipping characters from words. Right now I can't understand what you want. If you don't respect people here and don't care about checking what you have written, how can you expect someone to devote his time to help you?

prin
11th October 2010, 06:01
Hi,

In simple words, i just wanted to know that, if i need to implement this functionality of adding a linedit and combobox in a cell of a tablewidget.

1. Do i need to change the way i was initializing the tablewidgetitems, or should i just create a new Delegate class???
2. Does a delegate class plays any role in intializing the table items???
3. If it does plays a role in intializing tableitems then, how could i implement this functionality???

Help me, I m really a Newbie To QT.

Thanks!!!

prin
12th October 2010, 04:41
Hi,

In case we are creating a new class which inherits QItemDelegate class, then How can we maintain the QModelIndex and other options if we are using QTableWidget for displaying our data. And What is this qVariantfromValue( ), i mean what does it do???

tbscope
12th October 2010, 06:04
If the goal is to use the model in more than one view, then do not use a QTableWidget but a QTableView. The model always maintains the indexes. The view might keep a list of indexes to store view specific parameters (like expanded items), but if the view wants to change an item, it needs to tell the model about it.

The description of qVariantFromValue:
http://doc.qt.nokia.com/4.7/qvariant.html#qVariantFromValue

prin
13th October 2010, 06:08
Hi,

Thanks for replying,

I have few questions to ask about Delegates....

Earlier i was populating my tablewidget using SetItem(i, j, newItem) and Now(using Delegates) Do i need to Change the way i was populating my tablewidget???
if so, then how???

In createEditor function i have dynamically created a custom widget in which i have added one LineEdit and ComboBox in a widget, but when executing it..... the LineEdit and ComboBox size is too small.....

Thanks!!!!!!

prin
19th October 2010, 10:44
Hi,

I am still not getting the proper size of a custom widget in a cell. Its small and when i click to edit that cell, the background value is shown in the parent widget here is a screenshot of a single widget..5362 Can anyone help me??

How can i resize it, so that i will fit properly in a cell....

Thanks!!!!!

prin
19th October 2010, 11:33
Hey, Thanks all for replying to some of my threads...... My problem is solved...... :D