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. [Solved] Item delegates inactive problem
Forum Updated to NodeBB v4.3 + New Features

[Solved] Item delegates inactive problem

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 3.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.
  • T Offline
    T Offline
    t3chNo
    wrote on last edited by
    #1

    Hi, recently i realized that when window becomes inactive (focus on another window), item delegates in views seems active. First i experienced this problem in my project. I could not find a solution. Then i looked at the Qt Demos (Star Delegate Example) and same problem exists here too. Image that shows the problem: !http://s18.postimage.org/j5wsubtu1/image.png(problem)!

    Anybody knows a solution?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      Interesting question!

      First, I think you'd need to get a pointer to the widget you're painting on. You can do this directly by just adding an argument to the constructor of your delegate, or you might be able to retreive it via the painter argument of the paint() method (QPainter::device() returns a QPaintDevice*, which you could try to cast to a QWidget*).

      QWidget has a method isActiveWindow(). That should help you decide on the style to use for painting.

      Next thing to check is if activating/deactivating the window causes a repaint already or not. If not, you will have to trigger one. You should be able to do that by listening for the QEvent::WindowActivate and QEvent::WindowDeactivate events.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        t3chNo
        wrote on last edited by
        #3

        Afaik, when focus out from a view, delegates are repainted. But by major problem is i can't draw my delegate's background like the other columns. I'm drawing my delegate as a widget. A sample code:

        @
        void ValueItemDelegate::paint(QPainter *painter,
        const QStyleOptionViewItem &option,
        const QModelIndex &index) const
        {
        const Data data = index.data(Qt::DisplayRole).value<Data>();

        /* I created a designer form class (DataView) to ease painting. */
        DataView form(data);
        form.setAutoFillBackground(true);
        form.resize(option.rect.size());
        
        if (option.state & QStyle::State_Selected) {
            form.setBackgroundRole(QPalette::Highlight);
        } else {
            if (option.version > 1) {
                if (QStyleOptionViewItemV2(option).features & QStyleOptionViewItemV2::Alternate)
                    form.setBackgroundRole(QPalette::AlternateBase);
                else
                    form.setBackgroundRole(QPalette::Base);
            } else {
                form.setBackgroundRole(QPalette::Base);
            }
        }
        
        painter->drawPixmap(option.rect, QPixmap::grabWidget(&form, form.rect()));
        

        }
        @

        I tried setting a new palette that current color group is set to Inactive or Disabled. It didn't work. I looked for correct color roles and couldn't find one.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          So, it seems your real issue is that you can't seem to convince your form that it is disabled. I think what happens is that a widget sets the color group it uses for rendering itself. Setting it in advance would not work then. You could try to modify the palette by copying the values for Inactive to the values for the Active color group if the window is not the active window.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            t3chNo
            wrote on last edited by
            #5

            Copying palette's disabled or inactive colors to active colors did not work. It didn't even changed the colors.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              Could you show what you tried?

              1 Reply Last reply
              0
              • T Offline
                T Offline
                t3chNo
                wrote on last edited by
                #7

                Hey Andre, sorry for my late answer. I could not able to look at the code. I tried again to changing palette's active colors and it worked. I made a mistake last time. Thanks for your help.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #8

                  I'm glad you got it to work this time, and I'm happy to have been of help. Please mark the topic as '[Soved]' by editing your first post in this topic.

                  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