PDA

View Full Version : QScrollBar + setToolTip speed on display ... to slow



patrik08
25th February 2007, 20:42
I have write my own QSqlTableModel && QSqlRelationalDelegate (date edit)
If model update a query QScrollBar go to int 0 now i have reimplement a function to save
the last scroll ... & after 2 msec. i move QScrollBar to this position...
this run ok .... but if i display a ToolTip from Line nr. on QScrollBar this tips gomming after
1 or 2 sek. .. Question How i can make tis tooltips faster like Calc from openoffice 2?
Is here an event to handle?.....





signals:
public slots:
/* incomming last scroll position from table scroll int like row nr + 1 */
void RamScroll( int finder )
{
scroller->setToolTip(tr("Line nr. %1").arg(finder + 1));
if (permission) {
lastscrollpos = finder;
}
}
/* incomming emit sql update from model after update go to last line */
void IncommingUpdate( bool err , QString lastqueryupdate , int lastline )
{
permission = false;
oneditline = lastline;
///////////qDebug() << "### log sql " << lastscrollpos << " " << lastqueryupdate << " res->" << err;
/* wait a small piece by update model go line scroll 0 */
QTimer::singleShot(2, this, SLOT(ResetPermission()));
}
void ResetPermission() {
scroller->setValue(lastscrollpos);
tabi->setAlternatingRowColors(true);
tabi->resizeColumnsToContents();
tabi->selectRow( oneditline );
permission = true;
}
/* go to next limit x paintButton befor model */
void next()
{
int summrow = summRow() ;
showfrom = showfrom + limitfixrow;
paintButton();
model = new Beruf_model_A(db,showfrom,limitfixrow);
tabi->setModel(model);
connect( model , SIGNAL(OnUpdate(bool,QString,int)), this, SLOT(IncommingUpdate(bool,QString,int)));
scroller->setValue(0);
}
/* go to prev (if button enable) limit x paintButton befor model */
void prev()
{
int summrow = summRow() ;
showfrom = showfrom - limitfixrow;
paintButton();
model = new Beruf_model_A(db,showfrom,limitfixrow);
tabi->setModel(model);
connect( model , SIGNAL(OnUpdate(bool,QString,int)), this, SLOT(IncommingUpdate(bool,QString,int)));
scroller->setValue(0);
}


note:
This text is paste from window XP .... Not from ubuntu firefox .... buggi \n\n

wysota
26th February 2007, 09:01
I'd say that not resetting the model in the first place would be the easiest way to obtain your goal :)

Just don't inherit the model but embed it inside your own. Then when you do select() in the source model, simply update the model you expose. You can forward the rest of the calls from your "proxy" to the source model. This way you won't lose scrolling and selection at all.

You can try doing the same by subclassing the sql model and reimplementing select() but it might prove a lot harder.

patrik08
26th February 2007, 10:05
I'd say that not resetting the model in the first place would be the easiest way to obtain your goal :)
.

I dont have a select ..... if i make select by my own refresh() if i make select i have 1000 of row and i like only 100 .... and i testet setfilter (limit xx) ..... the way not running




Beruf_model_A::Beruf_model_A( QSqlDatabase dbin , int startat , int limit )
{
db = dbin;
setTable("table");
setEditStrategy(QSqlTableModel::OnRowChange);
limitrow = limit;
fromrow = startat;
updatepass = 0;
///////select();
refresh();
}


void Beruf_model_A::refresh()
{
QString sfsql;
sfsql = QString("SELECT * FROM table LIMIT %1,%2")
.arg(fromrow)
.arg(limitrow);
setQuery(sfsql);
setHeaderData(0, Qt::Horizontal, QObject::tr("fielda"));
...../* only header */

}

bool Beruf_model_A::setData(const QModelIndex &index, const QVariant &value, int role )
{
if (index.column() == 2 || index.column() > 12 ) {
return false;
}
QModelIndex primaryKeyIndex = QSqlQueryModel::index(index.row(), 2);
int id = data(primaryKeyIndex).toInt();
int lasteditingline = index.row();
bool ok;
QString saxi;
if (index.column() == 0) {
saxi = QString("update table set fielda = '%1' where ID = %2").arg(value.toString().toUpper()).arg(id);
} else if (index.column() == 1) {
saxi = QString("update table set fieldb = '%1' where ID = %2").arg(value.toInt()).arg(id);
/* .......else if 10 field.......... */
QSqlQuery query(saxi,db);
ok = query.exec();
refresh(); /* display new value */
updatepass++;
qDebug() << "### query " << query.lastQuery() << " fatto " << ok ;
emit OnUpdate(ok,query.lastQuery(),lasteditingline); /* if db2 is active send sincro */
return ok;
}




if i dont refresch refresh() model it display old value of field....

i suppose i have subclass a readonly model ....???




class Beruf_model_A : public QSqlTableModel
{
Q_OBJECT
public:
Beruf_model_A( QSqlDatabase dbin , int startat , int limit );
Qt::ItemFlags flags(const QModelIndex &index) const;
bool setData(const QModelIndex &index, const QVariant &value, int role);
inline int GetPassage() const { return updatepass; }
signals:
void OnUpdate( bool yes , QString sqlexc , int line );
private:
QString sql_Quote( QString xml );
QSqlDatabase db;
int updatepass;
int limitrow;
int fromrow;
void refresh();

};

/* date edit QDateTimeEdit */
class TabDelegate : public QSqlRelationalDelegate
{
Q_OBJECT

public:
TabDelegate( QObject *parent = 0);
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
private slots:
private:
};


/* QWidget wo call table */

oneditline = 0;
showfrom = 0;
limitfixrow = 100;
db = dbin;
model = new Beruf_model_A(dbin,showfrom,limitfixrow);
gridLayout = new QGridLayout(this);
gridLayout->setSpacing(6);
gridLayout->setMargin(9);
permission = true;

tabi = new QTableView(this);
tabi->setModel(model);
tabi->setItemDelegate(new TabDelegate(tabi));
tabi->setAlternatingRowColors(true);
tabi->resizeColumnsToContents();
scroller = tabi->verticalScrollBar();

wysota
26th February 2007, 10:59
I dont have a select .....
Sure you have. Every QSqlTableModel has one :) The point is to omit the default call (be it select() or setQuery() ), fetch the data yourself and sync the two models manually.


if i dont refresch refresh() model it display old value of field....
Because you have to update the model... just without calling select or setQuery, as they reset the model. Use insertRow, insertColumn, removeRow, removeColumn and setData instead.


i suppose i have subclass a readonly model ....???
No, nobody said that.

patrik08
26th February 2007, 14:02
Sure you have. Every QSqlTableModel has one :) The point is to omit the default call (be it select() or setQuery() ), fetch the data yourself and sync the two models manually.
.

OK ... if i make a default select and not !refresh on my own query...
How i set setQuery() && set filter( limit 100 row ) to grab only 100 line and not >1000?:confused: this setLimit() qt4 dont'have! not found on doc && not on book QT4 Molkentin && Jasmin books... && kde qt-copy demo or example && qt4 normal....

wysota
26th February 2007, 14:27
Try:

setFilter("1 LIMIT 0, 100");

Anyway that doesn't solve the original problem, does it?