Results 1 to 19 of 19

Thread: Qstyleditemdelegate probeme with Qcombobox

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2013
    Posts
    54
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Exclamation Qstyleditemdelegate probeme with Qcombobox

    Hi every boby

    i have probleme when i start implementing createEditor() function in Qstyleditemclass in Qtablewidget

    her
    Qt Code:
    1. QWidget *comboBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
    2. {
    3.  
    4. if(creeConnexion())
    5. {
    6. if(index.column() == 1 || index.column() == 0)
    7. {
    8. QComboBox *editor = new QComboBox(parent);
    9. editor->setEditable(true);
    10.  
    11. // Query data
    12. QSqlQuery *query = new QSqlQuery("select designation from Produit") ;
    13. while(query->next())
    14. editor->addItem(query->value(0).toString());
    15.  
    16. return editor;
    17. }
    18.  
    19. }else
    20. // the problem her, i want to return the default editor for other cells but , the app crashed when i user this code below
    21. return QStyledItemDelegate::createEditor(parent,option,index);
    22.  
    23. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jul 2013
    Posts
    54
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qstyleditemdelegate probeme with Qcombobox

    Plz i need your help

  3. #3
    Join Date
    Jul 2013
    Posts
    54
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qstyleditemdelegate probeme with Qcombobox

    i wait for your help

  4. #4
    Join Date
    Jul 2013
    Posts
    54
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qstyleditemdelegate probeme with Qcombobox

    Update thread !

  5. #5
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Qstyleditemdelegate probeme with Qcombobox

    What is creeConnexion()?
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  6. #6
    Join Date
    Jul 2013
    Posts
    54
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qstyleditemdelegate probeme with Qcombobox

    Quote Originally Posted by Santosh Reddy View Post
    What is creeConnexion()?
    It's a function to test the connexion on database

    her is the function

    Qt Code:
    1. static bool creeConnexion()
    2. {
    3. db = new QSqlDatabase;
    4. *db = QSqlDatabase::addDatabase("QSQLITE") ;
    5. db->setHostName("localhost");
    6. db->setDatabaseName("gestionstockDB.db");
    7. db->setPassword("");
    8. db->setUserName("");
    9. // Verifier l'ouverture de la base de donn�
    10. if(!db->open())
    11. {
    12. return false;
    13. }
    14. return true;
    15. }
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Qstyleditemdelegate probeme with Qcombobox

    So do you realy want to create and open new database connection each time an item in the table is edited? and are you deleting it when editor is done?

    You use QAbstractItemView::setItemDelegateForColumn(int column, QAbstractItemDelegate *delegate); only for the specific column, then you will not need to check the column number in the createEditor.

    I think you are missing to mention somthing else...
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. Do not paint selection in QStyledItemDelegate
    By jgirlich in forum Qt Programming
    Replies: 3
    Last Post: 4th March 2013, 10:33
  2. little problem with QStyledItemDelegate
    By Qiieha in forum Qt Programming
    Replies: 1
    Last Post: 26th November 2012, 09:21
  3. Replies: 1
    Last Post: 19th June 2012, 20:20
  4. QTreeView & QStyledItemDelegate
    By mentalmushroom in forum Qt Programming
    Replies: 0
    Last Post: 29th September 2011, 07:57
  5. Custom QStyledItemDelegate
    By Berryblue031 in forum Qt Programming
    Replies: 0
    Last Post: 2nd March 2011, 10:32

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
  •  
Qt is a trademark of The Qt Company.