PDA

View Full Version : QT 4.4 QGraphicsProxyWidget bridge Drag and Drop help



patrik08
26th March 2008, 08:36
I can not forward Drag and Drop is here more flag to set?

QGraphicsProxyWidget not forward events to subwidged




#include <QGraphicsScene>
#include <QtGui>
#include <QGraphicsProxyWidget>
#include <QGraphicsTextItem>
/* qt4.4 !! */


class Xedit : public QTextBrowser
{
Q_OBJECT
//
public:
Xedit::Xedit( QWidget* parent = 0 )
: QTextBrowser(parent)
{
setAcceptDrops(true);
}
void dragEnterEvent(QDragEnterEvent *event)
{
qDebug() << "### dragEnterEvent ";
/////event->acceptProposedAction();
insertFromMimeData(event->mimeData());
}
void insertFromMimeData ( const QMimeData * source )
{
/* external paste drag */
qDebug() << "### insertFromMimeData ";
if ( source->formats().contains("text/html") ) {
QString draghtml = source->html();
QTextDocumentFragment fragment = QTextDocumentFragment::fromHtml(draghtml);
textCursor().insertFragment(fragment);
return;
}
if ( source->hasText() ) {
textCursor().insertText(source->text());
return;
}
}

};

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

a.setOrganizationName("Dummy");
a.setOrganizationDomain("dummy.com");
a.setApplicationName("TestEventforward");
/////Xedit *extendededit = new Xedit;
///////extendededit->show();
QGraphicsScene scene;
QGraphicsView view(&scene);
view.show();
QWidget *editor = new QWidget;
QGridLayout *grid = new QGridLayout(editor);
Xedit *extendededit = new Xedit;
extendededit->setReadOnly(false);
extendededit->setOpenExternalLinks(false);
grid->addWidget(extendededit, 0, 0, 1, 1);
QGraphicsProxyWidget *proxy = scene.addWidget(editor);
/* http://doc.trolltech.com/main-snapshot/qgraphicsproxywidget.html */
proxy->setAcceptDrops( true );
////proxy->setAttribute( Qt::WA_AcceptDrops , true );
QGraphicsTextItem *text = scene.addText("Helo world..!");
text->setZValue(1.2);
extendededit->setDocument(text->document());

proxy->show();
proxy->setZValue(1.5);
a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
return a.exec();
}

#include "main.moc"

wysota
26th March 2008, 09:02
What do you mean "forward drag and drop"? Does the view accept drops?

patrik08
26th March 2008, 09:06
What do you mean "forward drag and drop"? Does the view accept drops?

if i run only class Xedit : public QTextBrowser drag and drop work
on QGraphicsProxyWidget inside QGraphicsScene i can edit and display correct,
but not Drag inside text image or other ....
the problem is only on drag and drop event... not comming in .

patrik08
26th March 2008, 10:50
What do you mean "forward drag and drop"? Does the view accept drops?

i not think that QGraphicsView must send all drag and drop event to his subitem?
but it works ...
i hope to not forward keyPressEvent and all other ...



void XhtmlView::dragEnterEvent ( QDragEnterEvent * e )
{
/* DivDiagram *CurrentActive; only xhtml <div> tag */
if (CurrentActive->id() > 0 && CurrentActive->ProxyBridgeEdit->isVisible()) {
CurrentActive->AdvanceEdit->wtxt->insertFromMimeData(e->mimeData());
return;
}
}

wysota
26th March 2008, 14:09
But did you enable drops for the view?

patrik08
27th March 2008, 07:27
But did you enable drops for the view?

Yes ... but i like only drag drop on subitem QGraphicsProxyWidget an his QWidget
the doc say : QGraphicsProxyWidget imo forum QTCLASS 4.4beta not found http://doc.trolltech.com/main-snapshot/qgraphicsproxywidget.html


The QGraphicsProxyWidget class provides a proxy layer for embedding a QWidget in a QGraphicsScene.
QGraphicsProxyWidget embeds any QWidget-based widget, for example, a QPushButton, QFontComboBox, or even QFileDialog, into QGraphicsScene. It forwards events between the two objects and translates between QWidget's integer-based geometry and QGraphicsWidget's qreal-based geometry. QGraphicsProxyWidget supports all core features of QWidget, including tab focus, keyboard input, Drag & Drop, and popups. You can also embed complex widgets, e.g., widgets with subwidgets.
QGraphicsProxyWidget takes care of automatically embedding popup children of embedded widgets through creating a child proxy for each popup. This means that when an embedded QComboBox shows its popup list, a new QGraphicsProxyWidget is created automatically, embedding the popup, and positioning it correctly.


I wand to build only a xhtml editor that processing div tag floating absolute and display it block or not...

wysota
27th March 2008, 08:59
It could be D&D related event passing through the proxy has not yet been implemented. We are talking about beta software here.

patrik08
27th March 2008, 09:14
It could be D&D related event passing through the proxy has not yet been implemented. We are talking about beta software here.

you know another way to display inside QGraphicsView / QGraphicsTextItem an exdended
xhtml editor? not beta?

wysota
27th March 2008, 11:24
Implement a custom QGraphicsItem.

patrik08
27th March 2008, 15:04
Implement a custom QGraphicsItem.


Now is running i drag drop from QGraphicsView and send to QGraphicsTextItem proxie..
to insert image or so..
And QGraphicsTextItem become 33 line to handle text from parent QAction on a simple way..



void DivDiagram::TextHandler()
{
QColor col;
QAction *invoice = qobject_cast<QAction *>(sender());
const double cases = invoice->data().toDouble();
QTextCursor c = QGraphicsTextItem::textCursor();
QTextCharFormat format = c.charFormat();
QFont f = format.font();
if (cases == 0.01) {
f.setBold(true);
} else if (cases == 0.02) {
f.setItalic(true);
} else if (cases == 0.03) {
f.setOverline(true);
} else if (cases == 0.04) {
f.setUnderline(true);
} else if (cases == 0.05) {
f.setStrikeOut(true);
} else if (cases == 0.06) {
col = QColorDialog::getRgba();
if (!col.isValid()) {
return;
}
format.setForeground(QBrush(col));
} else if (cases == 0.07) {
col = QColorDialog::getRgba();
if (!col.isValid()) {
return;
}
format.setBackground(QBrush(col));
} else if (cases > 3) {
f.setPointSizeF(cases);
} else {
return;
}
format.setFont(f);
c.setCharFormat(format);
}