void MainWindow::on_actionYearlyStatistics_triggered() { QTreeView *view = new QTreeView(); QAbstractItemModel *model = new YearlyStatisticsModel(); view->setModel(model); view->setWindowModality(Qt::NonModal); view->setMinimumWidth(600); view->setAttribute(Qt::WA_QuitOnClose, false); view->show(); }
int main(int argc, char *argv[]) { Q_INIT_RESOURCE(interview); QApplication app(argc, argv); QSplitter page; QAbstractItemModel *data = new Model(1000, 10, &page); QItemSelectionModel *selections = new QItemSelectionModel(data); QTableView *table = new QTableView; table->setModel(data); table->setSelectionModel(selections); table->horizontalHeader()->setMovable(true); table->verticalHeader()->setMovable(true); // Set StaticContents to enable minimal repaints on resizes. table->viewport()->setAttribute(Qt::WA_StaticContents); page.addWidget(table); QTreeView *tree = new QTreeView; tree->setModel(data); tree->setSelectionModel(selections); tree->setUniformRowHeights(true); tree->header()->setStretchLastSection(false); tree->viewport()->setAttribute(Qt::WA_StaticContents); // Disable the focus rect to get minimal repaints when scrolling on Mac. tree->setAttribute(Qt::WA_MacShowFocusRect, false); page.addWidget(tree); QListView *list = new QListView; list->setModel(data); list->setSelectionModel(selections); list->setViewMode(QListView::IconMode); list->setSelectionMode(QAbstractItemView::ExtendedSelection); list->setAlternatingRowColors(false); list->viewport()->setAttribute(Qt::WA_StaticContents); list->setAttribute(Qt::WA_MacShowFocusRect, false); page.addWidget(list); page.setWindowIcon(QPixmap(":/images/interview.png")); page.setWindowTitle("Interview"); page.show(); return app.exec(); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { //:/image/cat.jpg ui->setupUi(this); QString imagepath = ":/new/prefix1/folder.png"; QPixmap image0(imagepath); QPixmap image = image0.scaled(QSize(100,100)); qDebug() << image.size(); QIcon myIcon = QIcon(image); QSplitter *page= new QSplitter(); //customer QList<QVariant> title; title<<"one"<<"two"; QList<ItemObject*> values; GetData(values); data =new ItemModel(Q_NULLPTR); data->setHeaderTitle(title); data->BindingData(values); selections = new QItemSelectionModel(data); table = new QTableView; table->setModel(data); table->setSelectionModel(selections); table->setItemDelegate(new MyTableViewStyleDelegate()); table->horizontalHeader()->setSectionsMovable(true); table->setSelectionBehavior(QAbstractItemView::SelectRows); table->verticalHeader()->setSectionsMovable(true); table->horizontalHeader()->setStretchLastSection(true); // Set StaticContents to enable minimal repaints on resizes. table->viewport()->setAttribute(Qt::WA_StaticContents); table->setContextMenuPolicy(Qt::CustomContextMenu); connect(table, SIGNAL(customContextMenuRequested(QPoint)),SLOT(customMenuRequested(QPoint))); //table->setStyleSheet("QTableView{background-color: rgb(250, 250, 115);" "alternate-background-color: rgb(141, 163, 215);}"); //table->setItemDelegateForColumn(0,new MyLineItemDelegate()); table->setItemDelegateForColumn(0,new CheckBoxDelegate(table)); table->setItemDelegateForColumn(1,new ReadOnlyDelegate()); table->setSelectionBehavior(QAbstractItemView::SelectRows); table->setEditTriggers(QAbstractItemView::NoEditTriggers); table->setIconSize(QSize(1,1)); //header checkbox TableCheckedHeader *m_customHeader = NULL; m_customHeader = new TableCheckedHeader(Qt::Horizontal, this); table->setHorizontalHeader(m_customHeader); connect(m_customHeader, SIGNAL(toggled(bool)), this, SLOT(_headertoggled(bool))); page->addWidget(table); QTreeView *tree = new QTreeView; tree->setModel(data); tree->setSelectionModel(selections); tree->setUniformRowHeights(true); tree->header()->setStretchLastSection(false); tree->viewport()->setAttribute(Qt::WA_StaticContents); // Disable the focus rect to get minimal repaints when scrolling on Mac. tree->setAttribute(Qt::WA_MacShowFocusRect, false); page->addWidget(tree); list = new QListView; //QObject::connect(list,SIGNAL(doubleClicked(QModelIndex),this,SLOT(doubleClicked(QModelIndex)))); list->setModel(data); list->setIconSize(QSize(80,80)); list->setItemDelegate(new MyListItemDelegege()); list->setSelectionModel(selections); list->setSpacing(5); list->setViewMode(QListView::IconMode); list->setDragEnabled(false); list->setSelectionRectVisible(false); //list->setSelectionMode(QAbstractItemView::ExtendedSelection); list->setAlternatingRowColors(false); list->setResizeMode(QListWidget::Adjust); //list->viewport()->setAttribute(Qt::WA_StaticContents); list->setAttribute(Qt::WA_MacShowFocusRect, true); //list->setItemDelegateForColumn(1,new MyLineItemDelegate()); list->setEditTriggers(QAbstractItemView::NoEditTriggers); //menu list->setContextMenuPolicy(Qt::CustomContextMenu); connect(list,SIGNAL(customContextMenuRequested(QPoint)),SLOT(CustomListMenuRequested(QPoint))); page->addWidget(list); this->setCentralWidget(page); }