Guest User

QListWidget horizontal iconmode

a guest
Apr 6th, 2011
834
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <QtGui>
  2.  
  3. class TestDialog : public QDialog
  4. {
  5. public:
  6.     TestDialog()
  7.     {
  8.         QListWidget* contentsWidget = new QListWidget;
  9.         contentsWidget->setViewMode(QListView::IconMode);
  10.         contentsWidget->setFlow(QListView::LeftToRight);
  11.         contentsWidget->setWrapping(false);  
  12.         contentsWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); // Just to be sure
  13.         //contentsWidget->setItemDelegate(new ListViewDelegate());
  14.  
  15.         contentsWidget->setUniformItemSizes(true);
  16.        
  17.         contentsWidget->setIconSize(QSize(48, 48));
  18.         contentsWidget->setMovement(QListView::Static);
  19.        
  20.         contentsWidget->setMinimumWidth(400);
  21.         contentsWidget->setFixedHeight(80);
  22.         contentsWidget->setCurrentRow(0);
  23.        
  24.         QFileIconProvider fip;
  25.         // Some fancy icons
  26.         QListWidgetItem *testButton1 = new QListWidgetItem(contentsWidget);
  27.         testButton1->setIcon(fip.icon(QFileIconProvider::Computer));
  28.         testButton1->setText(tr("Test 1"));
  29.         testButton1->setTextAlignment(Qt::AlignHCenter | Qt::AlignBottom | Qt::AlignAbsolute);
  30.         testButton1->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
  31.        
  32.         QListWidgetItem *testButton2 = new QListWidgetItem(contentsWidget);
  33.         testButton2->setIcon(fip.icon(QFileIconProvider::Drive));
  34.         testButton2->setText(tr("Test 2"));
  35.         testButton2->setTextAlignment(Qt::AlignHCenter | Qt::AlignBottom | Qt::AlignAbsolute);
  36.         testButton2->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
  37.        
  38.         QListWidgetItem *testButton3 = new QListWidgetItem(contentsWidget);
  39.         testButton3->setIcon(fip.icon(QFileIconProvider::Desktop));
  40.         testButton3->setText(tr("Test 2"));
  41.         testButton3->setTextAlignment(Qt::AlignHCenter | Qt::AlignBottom | Qt::AlignAbsolute);
  42.         testButton3->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
  43.  
  44.         QSpacerItem *vSpacer1 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
  45.        
  46.         QVBoxLayout *dialogLayout = new QVBoxLayout(this);
  47.         dialogLayout->addWidget(contentsWidget);
  48.         dialogLayout->addItem(vSpacer1);
  49.        
  50.         setMinimumWidth(400);
  51.         setMinimumHeight(200);
  52.     }
  53. };
  54.  
  55. int main(int argc, char *argv[])
  56. {
  57.     QApplication app(argc, argv);
  58.  
  59.     TestDialog dialog;
  60.     return dialog.exec();
  61.  
  62. }
RAW Paste Data