Results 1 to 7 of 7

Thread: How to set a column readonly in qtablewidgetitem

  1. #1
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default How to set a column readonly in qtablewidgetitem

    Respected Sir/mMe,

    Sir/mMe i am facing problem in setting a column readonly in qt4. I think i have to use setFlag() function but what value is to be set as parameter to make column readonly i can't
    understand.
    Sir/mMe kindly inform me if i am right then what parameter to set or any other way to be used to set it readonly

    Thanking You All,
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to set a column readonly in qtablewidgetitem

    You can pass an OR combination of flags, like "Flag1 | Flag2". Pass any combination without Qt::ItemIsEditable.
    J-P Nurmi

  3. #3
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to set a column readonly in qtablewidgetitem

    Quote Originally Posted by jpn View Post
    You can pass an OR combination of flags, like "Flag1 | Flag2". Pass any combination without Qt::ItemIsEditable.
    QTableWidgetItem *__colItem = new QTableWidgetItem();
    __colItem->setText(QApplication::translate("schedulePlaylist ", "Playlist Name", 0, QApplication::UnicodeUTF8));
    __colItem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled|Q t::ItemIsDragEnabled|Qt::ItemIsDropEnabled|Qt::Ite mIsUserCheckable|Qt::ItemIsTristate);
    playlistTable->setHorizontalHeaderItem(0, __colItem);

    I am using above but It is not working!
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  4. #4
    Join Date
    Sep 2007
    Posts
    19
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to set a column readonly in qtablewidgetitem

    you don't have to pass all of the flags. just try to disable Qt::ItemIsEditable flag:
    __colItem->setFlags(__colItem->flags() &~ Qt::ItemIsEditable);

  5. The following user says thank you to nile.one for this useful post:

    ashukla (23rd October 2007)

  6. #5
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Question Re: How to set a column readonly in qtablewidgetitem

    Quote Originally Posted by nile.one View Post
    you don't have to pass all of the flags. just try to disable Qt::ItemIsEditable flag:
    __colItem->setFlags(__colItem->flags() &~ Qt::ItemIsEditable);
    I am using as follows;
    but it is not working!
    QTableWidgetItem *__colItem = new QTableWidgetItem();
    __colItem->setText(QApplication::translate("schedulePlaylist ", "Playlist Name", 0, QApplication::UnicodeUTF8));
    __colItem->setFlags(__colItem->flags() &~ Qt::ItemIsEditable);
    playlistTable->setHorizontalHeaderItem(0, __colItem);
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  7. #6
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to set a column readonly in qtablewidgetitem

    Qt::ItemIsSelectable|Qt::ItemIsEnabled should be enought,

    You should set those flags also for items inserted to widget, not only to headerItem.

  8. The following 2 users say thank you to mchara for this useful post:

    ashukla (23rd October 2007), sfryan (30th September 2011)

  9. #7
    Join Date
    Nov 2007
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to set a column readonly in qtablewidgetitem

    QTableWidget *myTableWidget = new QTableWidget;

    ...filling myTableWidget with QTableWidgetItems ...

    myTableWidget->setEditTriggers(QTableWidget::NoEditTriggers);
    Last edited by Timith; 8th November 2007 at 16:56.

Similar Threads

  1. Replies: 0
    Last Post: 10th November 2006, 13:46
  2. Interesting little Segfault w/r to signal/slot connection
    By Hydragyrum in forum Qt Programming
    Replies: 24
    Last Post: 12th September 2006, 19:22
  3. hidden QListView column suddenly visible
    By edb in forum Qt Programming
    Replies: 10
    Last Post: 27th January 2006, 08:00

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.