Results 1 to 15 of 15

Thread: QTableWidget + setCellWidget facing problem.

  1. #1
    Join Date
    Aug 2010
    Posts
    8
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Default QTableWidget + setCellWidget facing problem.

    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??

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QTableWidget + setCellWidget facing problem.

    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.

  3. The following user says thank you to Lykurg for this useful post:

    danish.ahmed (26th August 2010)

  4. #3
    Join Date
    Aug 2010
    Posts
    8
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: QTableWidget + setCellWidget facing problem.

    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???

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTableWidget + setCellWidget facing problem.

    Quote Originally Posted by danish.ahmed View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #5
    Join Date
    Aug 2010
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Symbian S60

    Default Re: QTableWidget + setCellWidget facing problem.

    There's the Star Delegate and the Spinbox Delegate examples in the Item View examples, those were pretty easy to understand .

  7. #6
    Join Date
    Aug 2010
    Posts
    8
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: QTableWidget + setCellWidget facing problem.

    Quote Originally Posted by wysota View Post
    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!!!

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTableWidget + setCellWidget facing problem.

    Read about QAbstractItemDelegate and its descendants.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. The following user says thank you to wysota for this useful post:

    danish.ahmed (24th September 2010)

  10. #8
    Join Date
    Oct 2010
    Posts
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: QTableWidget + setCellWidget facing problem.

    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.....

  11. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTableWidget + setCellWidget facing problem.

    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?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #10
    Join Date
    Oct 2010
    Posts
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: QTableWidget + setCellWidget facing problem.

    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!!!

  13. #11
    Join Date
    Oct 2010
    Posts
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: QTableWidget + setCellWidget facing problem.

    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???

  14. #12
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QTableWidget + setCellWidget facing problem.

    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...riantFromValue

  15. #13
    Join Date
    Oct 2010
    Posts
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: QTableWidget + setCellWidget facing problem.

    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!!!!!!

  16. #14
    Join Date
    Oct 2010
    Posts
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: QTableWidget + setCellWidget facing problem.

    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..widget.jpg Can anyone help me??

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

    Thanks!!!!!
    Last edited by prin; 19th October 2010 at 10:51.

  17. #15
    Join Date
    Oct 2010
    Posts
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: QTableWidget + setCellWidget facing problem.

    Hey, Thanks all for replying to some of my threads...... My problem is solved......

Similar Threads

  1. Replies: 7
    Last Post: 18th September 2009, 10:59
  2. I am facing a problem please help me !
    By sujan.dasmahapatra in forum General Programming
    Replies: 3
    Last Post: 16th September 2009, 14:12
  3. i am facing a problem with QTextEdit!!!
    By mismael85 in forum Qt Programming
    Replies: 9
    Last Post: 10th March 2008, 18:06
  4. Replies: 10
    Last Post: 9th July 2007, 22:02
  5. Facing problem with qt-4.1 designer
    By jnana in forum Qt Tools
    Replies: 4
    Last Post: 8th March 2006, 18:16

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.