Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Customiza ComboBox in QML
Qt 6.11 is out! See what's new in the release blog

Customiza ComboBox in QML

Scheduled Pinned Locked Moved Solved QML and Qt Quick
8 Posts 2 Posters 1.3k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    hi, i want to make a combobox like in the photo. When the Combobox is opened, I want to select only the country flags in the options, how can I do this?

    alt text

    raven-worxR 1 Reply Last reply
    0
    • ? A Former User

      hi, i want to make a combobox like in the photo. When the Combobox is opened, I want to select only the country flags in the options, how can I do this?

      alt text

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @NullByte
      you can customize ComboBox (QtQuickControls2)
      https://doc.qt.io/qt-5/qtquickcontrols2-customize.html#customizing-combobox

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      ? 1 Reply Last reply
      0
      • raven-worxR raven-worx

        @NullByte
        you can customize ComboBox (QtQuickControls2)
        https://doc.qt.io/qt-5/qtquickcontrols2-customize.html#customizing-combobox

        ? Offline
        ? Offline
        A Former User
        wrote on last edited by A Former User
        #3

        @raven-worx said in Customiza ComboBox in QML:

        @NullByte
        you can customize ComboBox (QtQuickControls2)
        https://doc.qt.io/qt-5/qtquickcontrols2-customize.html#customizing-combobox

        Thank you but it didn't work for me. I can't circle the pictures. Can you check my code?

        
        ComboBox {
            id: control
            model: ["https://flagcdn.com/128x96/ca.png", "https://flagcdn.com/128x96/tr.png", "https://flagcdn.com/128x96/ru.png"]
        
            contentItem: Rectangle {
                width: 24
                height: 24
                radius: 20
                clip: true
        
                Image {
                    anchors.fill: parent
                    source: control.currentValue
                    clip: true
                }
            }
        }
        
        
        
        raven-worxR 1 Reply Last reply
        0
        • ? A Former User

          @raven-worx said in Customiza ComboBox in QML:

          @NullByte
          you can customize ComboBox (QtQuickControls2)
          https://doc.qt.io/qt-5/qtquickcontrols2-customize.html#customizing-combobox

          Thank you but it didn't work for me. I can't circle the pictures. Can you check my code?

          
          ComboBox {
              id: control
              model: ["https://flagcdn.com/128x96/ca.png", "https://flagcdn.com/128x96/tr.png", "https://flagcdn.com/128x96/ru.png"]
          
              contentItem: Rectangle {
                  width: 24
                  height: 24
                  radius: 20
                  clip: true
          
                  Image {
                      anchors.fill: parent
                      source: control.currentValue
                      clip: true
                  }
              }
          }
          
          
          
          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by raven-worx
          #4

          @NullByte said in Customiza ComboBox in QML:
          clipping only works along item boundaries (x and y) - for performance reasons i guess.

          try this:

          contentItem: Item {
              width: 24
              height: 24
              
              Image {
                  id: img
          
                  anchors.fill: parent
                  source: control.currentValue
                  clip: true
          
                  layer.enabled: true
                  layer.effect: OpacityMask {
                       maskSource: mask
                 }
             }
             
             Rectangle {
                   id: mask
              
                   radius: 20
                   clip: true    
                   visible: false
                   anchors.fill: img
             }
          }
          

          or without the layer property, like in the docs.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          ? 1 Reply Last reply
          0
          • raven-worxR raven-worx

            @NullByte said in Customiza ComboBox in QML:
            clipping only works along item boundaries (x and y) - for performance reasons i guess.

            try this:

            contentItem: Item {
                width: 24
                height: 24
                
                Image {
                    id: img
            
                    anchors.fill: parent
                    source: control.currentValue
                    clip: true
            
                    layer.enabled: true
                    layer.effect: OpacityMask {
                         maskSource: mask
                   }
               }
               
               Rectangle {
                     id: mask
                
                     radius: 20
                     clip: true    
                     visible: false
                     anchors.fill: img
               }
            }
            

            or without the layer property, like in the docs.

            ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            @raven-worx said in Customiza ComboBox in QML:

            @NullByte said in Customiza ComboBox in QML:
            clipping only works along item boundaries (x and y) - for performance reasons i guess.

            try this:

            contentItem: Item {
                width: 24
                height: 24
                
                Image {
                    id: img
            
                    anchors.fill: parent
                    source: control.currentValue
                    clip: true
            
                    layer.enabled: true
                    layer.effect: OpacityMask {
                         maskSource: mask
                   }
               }
               
               Rectangle {
                     id: mask
                
                     radius: 20
                     clip: true    
                     visible: false
                     anchors.fill: img
               }
            }
            

            or without the layer property, like in the docs.

            @raven-worx It's not work for me. Check this.

            
            RowLayout {
                anchors.fill: parent
                spacing: 0
            
                ComboBox {
                    id: control
                    model: ["https://flagcdn.com/128x96/ca.png", "https://flagcdn.com/128x96/tr.png", "https://flagcdn.com/128x96/ru.png"]
            
                    Layout.leftMargin: 20
            
                    contentItem: Item {
                        width: 24 * dp
                        height: 24 * dp
            
                        Image {
                            id: img
                            anchors.fill: parent
                            source: control.currentValue
                            clip: true
            
                            layer.enabled: true
                            layer.effect: OpacityMask {
                                maskSource: mask
                            }
                        }
            
                        Rectangle {
                            id: mask
                            radius: 20
                            clip: true
                            visible: false
                            anchors.fill: img
            
                        }
                    }
                }
            }
            
            
            

            And result

            alt text

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              Any idea ?

              raven-worxR 1 Reply Last reply
              0
              • ? A Former User

                Any idea ?

                raven-worxR Offline
                raven-worxR Offline
                raven-worx
                Moderators
                wrote on last edited by
                #7

                @NullByte
                this works for me:

                ComboBox {
                        id: control
                        model: ["https://flagcdn.com/128x96/ca.png", "https://flagcdn.com/128x96/tr.png", "https://flagcdn.com/128x96/ru.png"]
                
                        contentItem: Item {
                            clip: true
                
                            Image {
                                id: img
                
                                height: parent.height
                                width: height
                                sourceSize {
                                    width: img.width
                                    height: img.height
                                }
                                source: control.currentValue
                                clip: true
                                fillMode: Image.PreserveAspectCrop
                
                                layer.enabled: true
                                layer.effect: OpacityMask {
                                    maskSource: mask
                                }
                            }
                
                            Rectangle {
                                id: mask
                                radius: 20
                                clip: true
                                visible: false
                                anchors.fill: img
                            }
                        }
                    }
                

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                1 Reply Last reply
                0
                • ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #8

                  It's work. Thanks

                  Result

                  alt text

                  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