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]How to style QComboBox's line edit?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]How to style QComboBox's line edit?

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 9.4k 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.
  • M Offline
    M Offline
    mbnoimi
    wrote on last edited by
    #1

    Hi,

    I want to style QComboBox's line edit using stylesheets but unfortunately I couldn't :(

    How can I fix this issue?

    I tried to use:
    [code]QComboBox > QWidget,
    QComboBox > QWidget > QWidget {
    font-size: 20pt;
    text-align: center;
    }[/code]

    I tried to use this too but it didn't change the font size while it applied the alignment!
    [code] ui->comboBox->lineEdit()->setAlignment(Qt::AlignHCenter);
    ui->comboBox->lineEdit()->setStyleSheet("font-size: 20pt;");[/code]

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Did you get a chance to visit Qt Help "here":http://qt-project.org/doc/qt-5/stylesheet-examples.html#customizing-qcombobox

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mbnoimi
        wrote on last edited by
        #3

        [quote author="Dheerendra" date="1404754282"]Did you get a chance to visit Qt Help "here":http://qt-project.org/doc/qt-5/stylesheet-examples.html#customizing-qcombobox[/quote]

        Sure dude. I tried to use the following but unfortunately it didn't apply the alignment:
        [code]QComboBox:editable {
        font-size: 20pt;
        text-align: center;
        }[/code]

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          Check this.

          @ QComboBox box;
          box.setEditable(true);
          box.lineEdit()->setReadOnly(true);
          box.lineEdit()->setAlignment(Qt::AlignCenter);

          box.addItem("pthinks.com");
          box.addItem("Dheeru");
          box.setStyleSheet("min-height: 2em;min-width: 10em;font: bold 20px;");@
          

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mbnoimi
            wrote on last edited by
            #5

            I wonder why text-align: center; doesn't work from the stylesheet?!

            I always prefer to user stylesheets

            1 Reply Last reply
            0
            • dheerendraD Offline
              dheerendraD Offline
              dheerendra
              Qt Champions 2022
              wrote on last edited by
              #6

              ComboBox is made up lineEdit. LineEdit itself provides flag to center the text. So internally it may not apply stylesheet to lineEdit component. You can get the lineEdit object from combobox and then try applying your stylesheet for lineEdit and I feel this is over kill.

              Dheerendra
              @Community Service
              Certified Qt Specialist
              http://www.pthinks.com

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mbnoimi
                wrote on last edited by
                #7

                Thank you guys.

                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