Results 1 to 13 of 13

Thread: I got it wrong, can't compile

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default I got it wrong, can't compile

    I tried following the MVF video but wasnt able to get what I wrote down to compile:

    main.cpp
    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "delegate.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. //Widget w;
    8. //w.show();
    9. ListDelegate *delegate;
    10. QListView view;
    11. view.setItemDelegate(delegate);
    12. view.show();
    13. return a.exec();
    14. }
    To copy to clipboard, switch view to plain text mode 

    delegate.h
    Qt Code:
    1. #ifndef DELEGATE_H
    2. #define DELEGATE_H
    3. #include <QtGui>
    4.  
    5. class ListDelegate : public QAbstractItemDelegate
    6. {
    7. public:
    8. ListDelegate(QObject *parent=0);
    9.  
    10. void paint(QPainter *painter,
    11. const QStyleOptionViewItem &option,
    12. const QModelIndex &index) const;
    13.  
    14. QSize sizeHint(const QStyleOptionViewItem &option,
    15. const QModelIndex &index)const;
    16. };
    17.  
    18. QSize ListDelegate::sizeHint(const QStyleOptionViewItem &option,
    19. const QModelIndex &index) const
    20. {
    21. return QSize(100,40);
    22. }
    23.  
    24. void ListDelegate::paint(QPainter *painter,
    25. const QStyleOptionViewItem &option,
    26. const QModelIndex &index) const
    27. {
    28. QColor background;
    29.  
    30. if(option.state & QStyle::State_Selected)
    31. background = Qt::darkRed;
    32. else
    33. background = Qt::lightGray;
    34.  
    35. painter->setFont(QFont("Arial",12,QFont::Bold));
    36. painter->drawText(option.rect, Qt::AlignCenter,
    37. index.model()->data(index).toString());
    38. }
    39. #endif // DELEGATE_H
    To copy to clipboard, switch view to plain text mode 

  2. The following user says thank you to been_1990 for this useful post:


Similar Threads

  1. What's wrong??
    By dreamer in forum Qt Programming
    Replies: 2
    Last Post: 25th June 2008, 08:07
  2. What's wrong with my actions???
    By fullmetalcoder in forum Qt Programming
    Replies: 6
    Last Post: 4th March 2007, 18:49
  3. What is wrong with this simple example ?
    By igor in forum Qt Programming
    Replies: 10
    Last Post: 16th January 2007, 11:26
  4. What's wrong with this connection??
    By SkripT in forum Qt Programming
    Replies: 4
    Last Post: 12th March 2006, 19:44
  5. Help please - what am I doing wrong?
    By Jimmy2775 in forum Qt Programming
    Replies: 6
    Last Post: 6th March 2006, 22:06

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.