Results 1 to 2 of 2

Thread: Size of button

  1. #1
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Size of button

    Hi All,

    I have made a delegate that will display a button at on every item in my QTreeView. I have provided the size hint of my button properly. What i want to accomplish is that I want my button to have a constant size, Since my treemodel contains only 1 column my button will increase/decrease according to width of my coloumn which I dont want to happen. How can i prevent this from happening?

    Note:
    I was painting the button its not a composite widget so i dont have size policy

    heres the code when i paint it
    Qt Code:
    1. void MyDelegate::paint(QPainter *painter,
    2. const QStyleOptionViewItem &option,
    3. const QModelIndex &index) const
    4. {
    5. const QAbstractItemModel *model = index.model();
    6. Q_ASSERT(model);
    7.  
    8. if (qVariantCanConvert<MyCustomsClass>(index.data(MyModel::DeviceInfoRole)))
    9. {
    10. MyCustomsClass info = qVariantValue<MyCustomsClass>(index.data(MyModel::DeviceInfoRole));
    11. QStyleOptionButton buttonOption;
    12.  
    13. buttonOption.state = option.state;
    14. #ifdef Q_WS_MAC
    15. buttonOption.state |= QStyle::State_Raised;
    16. #endif
    17. buttonOption.state &= ~QStyle::State_HasFocus;
    18.  
    19. buttonOption.rect = option.rect ;
    20. buttonOption.palette = option.palette;
    21. buttonOption.features = QStyleOptionButton::None;
    22. m_view->style()->drawControl(QStyle::CE_PushButton, &buttonOption, painter, m_view);
    23.  
    24. QStyleOption branchOption;
    25. static const int i = 9; // ### hardcoded in qcommonstyle.cpp
    26.  
    27. QRect r = option.rect;
    28.  
    29. branchOption.rect = QRect(r.left() + i/2, r.top() + (r.height() - i)/2, i, i);
    30. branchOption.palette = option.palette;
    31. branchOption.state = QStyle::State_Children;
    32.  
    33. // draw text
    34. QRect textrect = QRect(r.left() + i*2, r.top(), r.width() - ((5*i)/2), r.height());
    35. QString text = elidedText(option.fontMetrics, textrect.width(), Qt::ElideMiddle,
    36. info .name());
    37. m_view->style()->drawItemText(painter, textrect, Qt::AlignCenter,
    38. option.palette, m_view->isEnabled(), text);
    39.  
    40.  
    41.  
    42. }
    43. }
    To copy to clipboard, switch view to plain text mode 

    baray98
    Last edited by baray98; 3rd January 2008 at 18:35.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Size of button

    What is buttonOption.rect responsible for?

Similar Threads

  1. QLabel size policy
    By Caius Aérobus in forum Qt Programming
    Replies: 3
    Last Post: 7th December 2007, 17:57
  2. QSpinBox button size
    By dvmorris in forum Qt Programming
    Replies: 1
    Last Post: 13th August 2007, 08:20
  3. Replies: 1
    Last Post: 24th October 2006, 16:40
  4. change font size and button size of QMessageBox
    By nass in forum Qt Programming
    Replies: 6
    Last Post: 13th September 2006, 19:16
  5. Qt 4.1.1 linker warnings
    By Matt Smith in forum Installation and Deployment
    Replies: 0
    Last Post: 26th February 2006, 22:14

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.