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. Having an image and text in a QComboBox (QSS)
Forum Updated to NodeBB v4.3 + New Features

Having an image and text in a QComboBox (QSS)

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 917 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.
  • qwasder85Q Offline
    qwasder85Q Offline
    qwasder85
    wrote on last edited by qwasder85
    #1

    I'm trying to display a little image inside the text field of a QComboBox like this:

    QComboBox#folderSelectionComboBox
    {
        image: url(:Images/folderIcon.svg);
        image-position: left;
    }
    

    This works, but the text overlays the icon:
    alt text
    I tried adding a

    padding: 2 2 2 20;
    

    but that moves the text AND the image.
    Is there a way to move just the text in the box?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Im not sure we can move the text.

      What about

      QLineEdit* lineEdit = ui->combo->lineEdit();
      lineEdit->setClearButtonEnabled(true);
      lineEdit->addAction(":/:Images/folderIcon.svg", QLineEdit::LeadingPosition);

      qwasder85Q JonBJ 2 Replies Last reply
      2
      • mrjjM mrjj

        Hi
        Im not sure we can move the text.

        What about

        QLineEdit* lineEdit = ui->combo->lineEdit();
        lineEdit->setClearButtonEnabled(true);
        lineEdit->addAction(":/:Images/folderIcon.svg", QLineEdit::LeadingPosition);

        qwasder85Q Offline
        qwasder85Q Offline
        qwasder85
        wrote on last edited by qwasder85
        #3

        @mrjj Hm, lineEdit() keeps returning NULL, that's odd.

        Edit: Ah, the CBox has to be editable. I'll try that real quick.

        mrjjM 1 Reply Last reply
        0
        • qwasder85Q qwasder85

          @mrjj Hm, lineEdit() keeps returning NULL, that's odd.

          Edit: Ah, the CBox has to be editable. I'll try that real quick.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @qwasder85
          Sorry my bad. ( i didnt check docs)
          "Only editable combo boxes have a line edit."
          so if its not editable ( its a property ) then it returns null.

          qwasder85Q 1 Reply Last reply
          0
          • mrjjM mrjj

            @qwasder85
            Sorry my bad. ( i didnt check docs)
            "Only editable combo boxes have a line edit."
            so if its not editable ( its a property ) then it returns null.

            qwasder85Q Offline
            qwasder85Q Offline
            qwasder85
            wrote on last edited by
            #5

            @mrjj That works (the clear-button isn't needed), thank you! :)

            1 Reply Last reply
            1
            • mrjjM mrjj

              Hi
              Im not sure we can move the text.

              What about

              QLineEdit* lineEdit = ui->combo->lineEdit();
              lineEdit->setClearButtonEnabled(true);
              lineEdit->addAction(":/:Images/folderIcon.svg", QLineEdit::LeadingPosition);

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @mrjj said in Having an image and text in a QComboBox (QSS):

              lineEdit->setClearButtonEnabled(true);
              lineEdit->addAction(":/:Images/folderIcon.svg", QLineEdit::LeadingPosition);
              

              Both of these lines are cheating! It's not a "clear" button, and the docs also state the clear button is traling. Aren't you ashamed of yourself? ;-)

              mrjjM 1 Reply Last reply
              1
              • JonBJ JonB

                @mrjj said in Having an image and text in a QComboBox (QSS):

                lineEdit->setClearButtonEnabled(true);
                lineEdit->addAction(":/:Images/folderIcon.svg", QLineEdit::LeadingPosition);
                

                Both of these lines are cheating! It's not a "clear" button, and the docs also state the clear button is traling. Aren't you ashamed of yourself? ;-)

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @JonB
                Hehe well the clear button is an action so its not such a big
                hax. Except it clears nothing:)
                But if you use the Deco role of/on the items.. then it might become pretty weird :)

                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