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. Custom combo box look
QtWS25 Last Chance

Custom combo box look

Scheduled Pinned Locked Moved General and Desktop
9 Posts 5 Posters 3.8k Views
  • 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.
  • HarbH Offline
    HarbH Offline
    Harb
    wrote on last edited by Harb
    #1

    Hi!

    I want to make my custom delegate for one of the column of TableView. In this column user might choose Line Style(like Solid, Dot...) for each row. I have already implemented paint() event for delegate, so instead of integer numbers user see line itself. Now I want to implement setEditorData(), where I am going to use QComboBox as editor widget. The problem is that, when I set my custom delegate to QComboBox it effects only List but not PushButton. So in pup up list I see lines, and on PushButton I see just numbers 1,2,3...
    My question is what is the easiest way to display particular line on PushButton?

    1 Reply Last reply
    1
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Something's not clear, what PushButton ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      HarbH 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Something's not clear, what PushButton ?

        HarbH Offline
        HarbH Offline
        Harb
        wrote on last edited by
        #3

        @SGaist QComboBox consist of button and a list. This is mentioned in documentation http://doc.qt.io/qt-5/qcombobox.html#details There is an underlying QStandardItemModel and QListView used in QComboBox. I have implemented my own delegate, which paint different style lines instead of integer numbers. The problem is that when I set this delegate to QComboBox the appearance of QListView is changing but button still display integer number instead of line.

        Fore example in Color Editor Factory Example http://doc.qt.io/qt-5/qtwidgets-itemviews-coloreditorfactory-example.html
        there is a list of colors witch looks like square of particular color, and the name of color. But on the top of the list (widget witch looks like a button with an arrow), there is only name. So my question is about changing appearance of this button.

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          The delegate only paints items in the popup list.
          The button part is styled depending on the platform. If you want custom painting of the widget itself then subclass QComboBox and override paintEvent.

          HarbH 1 Reply Last reply
          1
          • Chris KawaC Chris Kawa

            The delegate only paints items in the popup list.
            The button part is styled depending on the platform. If you want custom painting of the widget itself then subclass QComboBox and override paintEvent.

            HarbH Offline
            HarbH Offline
            Harb
            wrote on last edited by Harb
            #5

            @Chris-Kawa It means that I will have to write all paint routine on very low level from scratch, no other way? I hoped that there was a way just to add a little code and paint a line on the button.

            Joel BodenmannJ 1 Reply Last reply
            0
            • HarbH Harb

              @Chris-Kawa It means that I will have to write all paint routine on very low level from scratch, no other way? I hoped that there was a way just to add a little code and paint a line on the button.

              Joel BodenmannJ Offline
              Joel BodenmannJ Offline
              Joel Bodenmann
              wrote on last edited by Joel Bodenmann
              #6

              @Harb you can overwrite the paint() as @Chris-Kawa suggested, then first call the standard implementation in there using QComboBox::paint() and then you can draw your line over the standard button that was rendered for you.

              Something like:

              MyComboBox::paint(...)
              {
                  // Render the default combo box
                  QComboBox::paint(...);
              
                  // Draw your stuff over it
                  painter->drawLine(...);
              }
              

              Industrial process automation software: https://simulton.com
              Embedded Graphics & GUI library: https://ugfx.io

              HarbH 1 Reply Last reply
              1
              • Joel BodenmannJ Joel Bodenmann

                @Harb you can overwrite the paint() as @Chris-Kawa suggested, then first call the standard implementation in there using QComboBox::paint() and then you can draw your line over the standard button that was rendered for you.

                Something like:

                MyComboBox::paint(...)
                {
                    // Render the default combo box
                    QComboBox::paint(...);
                
                    // Draw your stuff over it
                    painter->drawLine(...);
                }
                
                HarbH Offline
                HarbH Offline
                Harb
                wrote on last edited by
                #7

                @Joel-Bodenmann Wow, tnx! Yes, it will work!

                1 Reply Last reply
                0
                • N Offline
                  N Offline
                  NicuPopescu
                  wrote on last edited by NicuPopescu
                  #8

                  Hi,
                  may be it will work, but when a QComboBox it is used as an editor in a table view item delegate things work other way.
                  Do you understand that because the push button/text edit overlays the table view item's surface then the appearance of both are the same and the painting could simply be done by the table view item delegate? Moreover the QComboBox could insert icons( pixmaps ) in the list so there might be no need of subclassing? ... the discussion started about a table view and a QComboBox editor, all together, then switched to the isolated case of a custom QComboBox, which is not the same. Again, because the table view item delegate will do the final painting, the editor will be closed and destroyed, there could be some mismatch between the two paintings ...

                  1 Reply Last reply
                  0
                  • Chris KawaC Offline
                    Chris KawaC Offline
                    Chris Kawa
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @NicuPopescu True. In that case the custom overpainting can be done in some static method of the subclassed combo and then called from both the paintEvent of the combo and paint of the delegate.

                    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