Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How can I get the Button drawed by QApplication::style()->drawControl or connect it's signal to a function?

How can I get the Button drawed by QApplication::style()->drawControl or connect it's signal to a function?

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jzq740176597
    wrote on last edited by
    #1

    @class CIconButtonDelegate : public QItemDelegate //QStyledItemDelegate for style to draw [by jzq]
    {
    public:
    CIconButtonDelegate(QWidget *parent =0 ): QItemDelegate(parent){}
    // painting
    void paint(QPainter *painter,
    const QStyleOptionViewItem &option, const QModelIndex &index) const
    {
    QStyleOptionButton button;
    button.rect = option.rect;//QRect(x,y,w,h);
    //button.text = "=^.^=";
    QIcon icon (index.data().toString());
    if(icon.isNull())
    icon =QIcon(CConfig::instance()->getImageDir() + "graphicitems/sf.png");
    button.icon = icon;
    button.state = QStyle::State_Enabled;

    QApplication::style()->drawControl( QStyle::CE_PushButton, &button, painter);
    }@

    what i want is custom Button item delegate for the view. when is clicked, it will trigger a dlg to choose a new png-file.
    and update button 's Icon as the new png.

    edit: My current workAround , override the editorEvent(...)

    @ bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
    {
    if(event->type() == QEvent::MouseButtonPress){//单击
    QMouseEvent * e = (QMouseEvent *)event;
    if(e->button() == Qt::LeftButton){
    //... trigger the dlg for choose png file
    }
    @
    Thanks in advance!

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved