Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. DoubleClick event on specific fields in QSqlQueryModel
Forum Updated to NodeBB v4.3 + New Features

DoubleClick event on specific fields in QSqlQueryModel

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 556 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Scott KriseS Offline
    Scott KriseS Offline
    Scott Krise
    wrote on last edited by
    #1

    Hello Everyone,

    So I want to be able to capture a doubleclick event from a field within a QSqlQueryModel. Here is my code to create my voucher model:

    vouchermodel = new QSqlQueryModel;
    vouchermodel->setQuery(updateStr);
    
    vouchermodel->setHeaderData(0, Qt::Horizontal, QObject::tr("Voucher"));
    vouchermodel->setHeaderData(1, Qt::Horizontal, QObject::tr("Date"));
    vouchermodel->setHeaderData(2, Qt::Horizontal, QObject::tr("Amount"));
    vouchermodel->setHeaderData(3, Qt::Horizontal, QObject::tr("Due"));
    vouchermodel->setHeaderData(4, Qt::Horizontal, QObject::tr("G/L#"));
    vouchermodel->setHeaderData(5, Qt::Horizontal, QObject::tr("Vendor Inv"));
    vouchermodel->setHeaderData(6, Qt::Horizontal, QObject::tr("Check #"));
    vouchermodel->setHeaderData(7, Qt::Horizontal, QObject::tr("Check Date"));
    
    voucherTableView->setModel(vouchermodel);
    voucherTableView->resizeColumnsToContents();
    voucherTableView->verticalHeader()->hide();
    voucherTableView->show();
    connect(voucherTableView->selectionModel(), SIGNAL(currentVoucherChanged(const QModelIndex &,const QModelIndex &)),
            this, SLOT(currentReceiptChanged(const QModelIndex &)));
    

    So, for example, I want the user to be able to double click any voucher being displayed in this area, and I want to have a procedure set up that will open the voucher maintenance screen and have the voucher they clicked on be displayed. Additionally, I also might want to allow them to double click the vendor invoice field on the same record and pass that information to a procedure that might display a scanned copy of that invoice, and so on.

    How must i change my above code to allow for this to happen?

    JonBJ 1 Reply Last reply
    0
    • Scott KriseS Scott Krise

      Hello Everyone,

      So I want to be able to capture a doubleclick event from a field within a QSqlQueryModel. Here is my code to create my voucher model:

      vouchermodel = new QSqlQueryModel;
      vouchermodel->setQuery(updateStr);
      
      vouchermodel->setHeaderData(0, Qt::Horizontal, QObject::tr("Voucher"));
      vouchermodel->setHeaderData(1, Qt::Horizontal, QObject::tr("Date"));
      vouchermodel->setHeaderData(2, Qt::Horizontal, QObject::tr("Amount"));
      vouchermodel->setHeaderData(3, Qt::Horizontal, QObject::tr("Due"));
      vouchermodel->setHeaderData(4, Qt::Horizontal, QObject::tr("G/L#"));
      vouchermodel->setHeaderData(5, Qt::Horizontal, QObject::tr("Vendor Inv"));
      vouchermodel->setHeaderData(6, Qt::Horizontal, QObject::tr("Check #"));
      vouchermodel->setHeaderData(7, Qt::Horizontal, QObject::tr("Check Date"));
      
      voucherTableView->setModel(vouchermodel);
      voucherTableView->resizeColumnsToContents();
      voucherTableView->verticalHeader()->hide();
      voucherTableView->show();
      connect(voucherTableView->selectionModel(), SIGNAL(currentVoucherChanged(const QModelIndex &,const QModelIndex &)),
              this, SLOT(currentReceiptChanged(const QModelIndex &)));
      

      So, for example, I want the user to be able to double click any voucher being displayed in this area, and I want to have a procedure set up that will open the voucher maintenance screen and have the voucher they clicked on be displayed. Additionally, I also might want to allow them to double click the vendor invoice field on the same record and pass that information to a procedure that might display a scanned copy of that invoice, and so on.

      How must i change my above code to allow for this to happen?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Scott-Krise
      At the broadest level, are you clear that the UI interaction (e.g. double-click) will be handled through your voucherTableView (QTableView?), rather than the QSqlQueryModel you ask about? So that's where to look in docs. From there you will get the field in the model the user has clicked on, and pass that on to other code.

      1 Reply Last reply
      3
      • Scott KriseS Offline
        Scott KriseS Offline
        Scott Krise
        wrote on last edited by
        #3

        Ah, no...that wasn't clear. I thought it would be handled differently for the QSqlQueryModel...and I couldn't find any documentation on that. Ill see if I can find what I need in the documentation.

        Thanks!

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MrShawn
          wrote on last edited by
          #4

          As @JonB just said, generally speaking the view is what interacts with the user.

          Your view inherits from QAbstractItemView which has the signal you are looking for, it will send the QModelIndex that you can use to access the data and other stuff.

          Good luck :)

          1 Reply Last reply
          2
          • Scott KriseS Offline
            Scott KriseS Offline
            Scott Krise
            wrote on last edited by
            #5

            I got it working. Thank you!!

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved