Display HTML As Text, Change BBCode to Display as HTML JQuery/JS
Date : March 29 2020, 07:55 AM
wish of those help Set the target's text() with the full text; so your HTML tags will be encoded. Then do the BBCode replacement on the encoded HTML: $('#posttextareadisplay').text( $('#textareainput').val() );
var replacebbcode = $('#posttextareadisplay').
html().
replace(/(\[((\/?)(b|u|i|s|sub|sup))\])/gi, '<$2>');
$('#posttextareadisplay').html( replacebbcode );
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<textarea name="" id="textareainput" cols="30" rows="10">
[b]bold[/b] <bold>bold</bold>
</textarea>
<p id="posttextareadisplay"></p>
|
How to set QTreeWidgetItem as not Editable
Tag : python , By : Trevor Cortez
Date : March 29 2020, 07:55 AM
hope this fix your issue You just have to perform the inverse operation you did as the Qt flags are bitwise. item.setFlags(item.flags() & ~QtCore.Qt.ItemIsEditable)
|
How to get QTreeWidgetItem position?
Tag : qt , By : Angelo Giannatos
Date : March 29 2020, 07:55 AM
hope this fix your issue If you have a QTreeWidgetItem * pitem you can use QTreeWidget::visualitemRect... QRect viewport_relative_rect = pitem->treeWidget()->visualItemRect(pitem);
|
Parent a QTreeWidgetItem to an existing QTreeWidgetItem to second column maintaining the first column
Tag : python , By : Neuromaster
Date : March 29 2020, 07:55 AM
Hope that helps You could set the check boxes to the second column in your QTreeWidget and swap the first and second sections of the header, e.g. from PySide2 import QtWidgets, QtCore
class MyItem(QtWidgets.QTreeWidgetItem):
def __init__(self, label):
super().__init__([label, ''])
self.setCheckState(1, QtCore.Qt.Unchecked)
self.setFlags(self.flags() | QtCore.Qt.ItemIsAutoTristate)
class MyTree(QtWidgets.QTreeWidget):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.setColumnCount(2)
self.header().swapSections(1,0)
self.header().resizeSection(1, 80)
if __name__ == "__main__":
app = QtWidgets.QApplication([])
tree = MyTree()
tree.setHeaderLabels(['label', 'checked'])
items = [MyItem(f'item {i}') for i in range(6)]
tree.insertTopLevelItems(0, items)
for i, item in enumerate(items):
for j in range(4):
items[i].addChild(MyItem(f'item {i}-{j}'))
tree.show()
app.exec_()
|
QWidget in QTreeWidgetItem disappearing after reordering the QTreeWidgetItem
Tag : cpp , By : kuba53280
Date : March 29 2020, 07:55 AM
this will help Why are widgets deleted? When the drag and drop is performed, the data of the selected items is coded (roles and associated values) and saved in a QMimeData. When the drop is accepted, the source items are deleted and new items are created with the information stored in the QMimeData, inside the saved information there is no widgets information since this does not have relation with the model. And since the items are deleted, their widgets are also deleted. #include <QApplication>
#include <QLabel>
#include <QTreeWidget>
#include <QDebug>
static void on_destroyed(){
qDebug()<<"destroyed";
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTreeWidget w;
w.setSelectionMode(QAbstractItemView::SingleSelection);
w.setDragEnabled(true);
w.viewport()->setAcceptDrops(true);
w.setDropIndicatorShown(true);
w.setDragDropMode(QAbstractItemView::InternalMove);
for(int i=0; i< 5; i++){
QTreeWidgetItem *it = new QTreeWidgetItem(&w);
QLabel *lbl = new QLabel(QString::number(i));
QObject::connect(lbl, &QObject::destroyed, on_destroyed);
w.setItemWidget(it, 0, lbl);
}
w.show();
return a.exec();
}
#include <QApplication>
#include <QStandardItemModel>
#include <QTreeView>
#include <QHeaderView>
#include <QDropEvent>
#include <QStyledItemDelegate>
#include <QLineEdit>
class ToolsSelectorDelegate: public QStyledItemDelegate{
public:
using QStyledItemDelegate::QStyledItemDelegate;
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const{
QLineEdit *le = new QLineEdit(parent);
return le;
}
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const{
QRect r(option.rect);
r.adjust(2, 2, -2, -2);
editor->setGeometry(r);
}
};
class ToolsSelectorWidget: public QTreeView{
QStandardItemModel model;
public:
ToolsSelectorWidget(QWidget *parent=nullptr): QTreeView(parent){
setItemDelegate(new ToolsSelectorDelegate(this));
setModel(&model);
header()->hide();
setSelectionMode(QAbstractItemView::SingleSelection);
setDragEnabled(true);
viewport()->setAcceptDrops(true);
setDropIndicatorShown(true);
setDragDropMode(QAbstractItemView::InternalMove);
for(int i=0; i<4; ++i) {
QList<QStandardItem *> items;
for(const QString & text: {"Preview", "Name", "Visible", "Locked"}){
QStandardItem *it = new QStandardItem(QString("Part%1 %2").arg(i).arg(text));
it->setFlags(it->flags() & ~Qt::ItemIsDropEnabled & ~Qt::ItemIsEditable);
items.append(it);
if(text == "Visible" || text == "Locked"){
it->setFlags(it->flags() | Qt::ItemIsUserCheckable);
it->setCheckState(Qt::Unchecked);
}
else if (text == "Name") {
it->setFlags(it->flags() | Qt::ItemIsEditable);
}
}
for(const QString & children: {"The", "quick", "Brown", "fox", "jump...", "over", "the", "lazy", "dog"})
items.first()->appendRow(new QStandardItem(children));
model.invisibleRootItem()->appendRow(items);
for( int i = 0; i < model.rowCount(); ++i )
openPersistentEditor(model.index(i, 1));
}
}
protected:
void dropEvent(QDropEvent *event) {
QModelIndex droppedIndex = indexAt(event->pos());
if( !droppedIndex.isValid() || droppedIndex.parent().isValid())
return;
QTreeView::dropEvent(event);
}
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
ToolsSelectorWidget w;
w.show();
return a.exec();
}
|