PDA

View Full Version : problem with QGraphicsProxyWidget



dreamer
19th May 2008, 16:18
I reimplement my custom QGraphicsProxyWidget and i add it in my custom scene.
I reimplement the mousemove, mousepress and mouserelease event but i can't move it in my scene......why???

here the code:


void myproxy::mouseMoveEvent(QGraphicsSceneMouseEvent *event){
QGraphicsProxyWidget::mouseMoveEvent(event);
}
void myproxy::mouseReleaseEvent(QGraphicsSceneMouseEven t *mouseEvent){
QGraphicsProxyWidget::mouseReleaseEvent(mouseEvent );
}
void myproxy::mousePressEvent ( QGraphicsSceneMouseEvent * mouseEvent ){
scene()->clearSelection();
setSelected(true);
setCursor(Qt::ClosedHandCursor);

QGraphicsProxyWidget::mousePressEvent(mouseEvent);
}


i also set this flag in the constructor:


setFlag(QGraphicsProxyWidget::ItemIsMovable, true);
setFlag(QGraphicsProxyWidget::ItemIsSelectable, true);
setFlag(QGraphicsProxyWidget::ItemIsFocusable, true);

patrik08
19th May 2008, 16:58
You can not move the proxie!
Only QGraphicsItem family can move on


void TextLayer::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if (!IsSelectActive) {
return;
}
if (modus == Lock) {
return;
}
if (format == DIV_ABSOLUTE) {
if (modus == Move ) {
/* move resize top left frozing */
bool ChangeXY;
QGraphicsItem::setCursor(Qt::SizeAllCursor);
/* move from stop xy */
//////qDebug() << " move layer status ...............";
qreal WWxi = event->pos().x() - event->lastPos().x();
qreal HHyi = event->pos().y() - event->lastPos().y();
qreal diff = qMax ( HHyi , WWxi );
if (diff > 0) {
SetDimension( wi + WWxi , hi + HHyi );
ChangeXY = true;
} else {
if (wi > 100 && hi > 20) {
if (WWxi < 0) {
SetDimension( wi - 1 ,hi);
} else if (HHyi < 0) {
SetDimension( wi ,hi - 1);
}
ChangeXY = true;
}
}
/* normal move */
} else if ( modus == MoveAll ) {
if (!mount->txtControl()->editable()) {
QGraphicsItem::setCursor(Qt::ClosedHandCursor);
setPos(event->scenePos() - event->lastPos());
event->accept();
}
}
}
ShowInfos();
if (mount->txtControl()->editable()) {
mount->txtControl()->procesevent(event);
}
QGraphicsItem::mouseMoveEvent(event);
}



or flags

QGraphicsProxyWidget become parent QGraphicsScene is not normal event!



void resizeEvent(QResizeEvent *event)
{
QGraphicsView::resizeEvent(event);
fitInView(scene->sceneRect(), Qt::KeepAspectRatio);
}


demo /4.4.0_src/examples/graphicsview/padnavigator


you can try to static_cast from QEvent *e bool :: sceneEvent(QEvent *event) parent item

dreamer
19th May 2008, 18:15
How can i add to my scene a "table with rows and columns" using QGraphicsproxywidget??

adding a QTableWidget to my scene, i don't obtain the right behaviour.....that is
when i resize it, also the column and rows have to resize.....i'd also don't like to have the horizontal and vertical header, but just the columns and rows.

So i search an object like a QGraphicsRectItem filled with rows and columns......
How can i build it?

patrik08
19th May 2008, 19:21
what is your target sql table? image table? or print table? calendar....

point your mouse here ... it can make table....
http://www.qt-apps.org/content/show.php/GraphicsViewEdit+Layer?content=80234

dreamer
19th May 2008, 21:01
looking for the code, he adds the table using html language!!!!!!



void Layoutpainter::CreateanewTable()
{

QString subtext, collx, rowx,largo;
bool ok;
int colonne = QInputDialog::getInteger(0, tr("New Table cool"),tr("Cool:"), 3, 1, 10, 1, &ok);
int righe = QInputDialog::getInteger(0, tr("New Table row"),tr("Row:"), 3, 1, 100, 1, &ok);
largo = "100%";
if (colonne > 0 && righe > 0) {
QStringList tables;
tables.clear();
tables.append(QString("<table border=\"1\" align=\"left\" width=\"%1\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#ffffff\">").arg(largo));
for (int i=0;i<righe;i++){
tables.append(QString("<tr>"));
for (int o=0;o<colonne;o++){
tables.append(QString("<td><p></p></td>"));
}
tables.append(QString("</tr>"));
}
tables.append(QString("</table>"));

subtext = tables.join("\n");
QTextDocumentFragment fragment = QTextDocumentFragment::fromHtml(subtext);
textCursor().insertFragment(fragment);
}
}


I think it isn't a great solution for me!! I'd like an image table(i don't have to fill it with any text), but i'd just like to set the number of columns and rows and their width.................

patrik08
19th May 2008, 22:25
another way is
from QStandardItemModel > QTextDocument

http://fop-miniscribus.googlecode.com/svn/trunk/http_debugger.1.0/ModelSwap.h
http://fop-miniscribus.googlecode.com/svn/trunk/http_debugger.1.0/ModelSwap.cpp

and from QTextDocument to image.... QTextDocument->drawContents(device,qrect);