C++ (Qt)void CPlotter2d::paintEvent(QPaintEvent * /* event */){ QStylePainter painter(this); painter.drawPixmap(0, 0,pixmap);// mg);*/ //refreshPixmap(opt_graph); } void CPlotter2d::resizeEvent(QResizeEvent * /* event */){ opt_graph.width_widget = this->size().width(); opt_graph.height_widget = this->size().height(); pixmap= refreshPixmap(opt_graph); // refreshPixmap(opt_graph);}
C++ (Qt)void CPlotter2d::resizeEvent(QResizeEvent * /* event */){ if(opt_graph.width_widget != this->size().width() || opt_graph.height_widget != this->size().height() ) { opt_graph.width_widget = this->size().width(); opt_graph.height_widget = this->size().height(); pixmap= refreshPixmap(opt_graph); } // refreshPixmap(opt_graph);}
C++ (Qt)#include "clistwidgetlegendgraph2d.h"#include <QtGui/QApplication> int main(int argc, char *argv[]){ QApplication a(argc, argv); QGraphicsScene scene(QRect(0,0,640,480)); CListLegend list(0); list.addItems(QStringList()<<"sfdsdfshhhhhhhhhhhhhhhhdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"); scene.addWidget(&list); scene.addWidget(new QPushButton("button",0)); QPixmap pixmap; QPainter painter(&pixmap); painter.setRenderHint(QPainter::Antialiasing); scene.render(&painter); painter.end(); pixmap.save("scene.png"); QGraphicsView view(&scene); view.show(); return a.exec();}
C#include <QtGui> class CListLegend: public QListWidget{ Q_OBJECTpublic: CListLegend(QWidget *parent):QListWidget(parent) { setSelectionMode(QAbstractItemView::SelectionMode::NoSelection); setSelectionRectVisible(false); setFocusPolicy( Qt::NoFocus ); setFrameShape(QFrame::Box); QPixmap image(10,10); resize(100,80); image.fill(2); addItem(image,"fffjjjjjjjjjjjjddddddddjjjjjjjjjjjjjjjj",Qt::CheckState::Unchecked); addItem(image,"fffjjjjjjjjjjjjjjjjjjjjjjjjjjjj",Qt::CheckState::Unchecked); addItem(image,"fffjjjjjjjjjjjjjjjjjjjjjjjjjjjj",Qt::CheckState::Unchecked); addItem(image,"fffjjjjjjjjjjjjj",Qt::CheckState::Unchecked); addItem(image,"fffjjjjjjjjjjjjjjj",Qt::CheckState::Unchecked); addItem(image,"fffjjjjjjjjjjjjjjjj",Qt::CheckState::Unchecked); addItem(image,"fffjjjjjjjjjjjjjjjjjjjjjjjjjjjj",Qt::CheckState::Unchecked); } void addItem(const QIcon& icon, const QString& str, Qt::CheckState state = Qt::CheckState::Unchecked) { QListWidget::addItem(new QListWidgetItem(str)); // item(count()-1)->setCheckState(state); } bool event(QEvent * ev) { switch( ev->type() ) { case QEvent::Enter: setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded); setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOn ); QListWidget::update(); break; case QEvent::Leave: setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); QListWidget::update(); break; default: break; } return QListWidget::event( ev ); } QPixmap image() { return QPixmap().grabWidget(this); } };