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. QComboBox how to change tab stop width?

QComboBox how to change tab stop width?

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

    Hello,

    in a QComboBox each item string consists of two parts. And the second string part should be aligned to the second string parts of all following combobox rows.

    I tried to achieve this using a tabulator (\t) in the item strings. But the tabulator width is too large and I couldn't find a way to change it:

    #include <QApplication>
    #include <QWidget>
    #include <QComboBox>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        QWidget w;
    
        QComboBox combo1(&w);
        combo1.setStyleSheet("QComboBox { combobox-popup: 0; }");
        combo1.setFont(QFont("Roboto",10));
        combo1.setGeometry(20,20,300,25);
    
        QString string1("A\t:Something");
        combo1.addItem(string1);
    
        QString string2("DNX\t:Something");
        combo1.addItem(string2);
    
        QString string3("B\t:Something");
        combo1.addItem(string3);
    
        QString string4("KLQ\t:Something");
        combo1.addItem(string4);
    
        QString string5("GT\t:Something");
        combo1.addItem(string5);
    
        QString string6("F\t:Something");
        combo1.addItem(string6);
    
        w.show();
        w.resize(340, 200);
        return a.exec();
    }
    

    This is how it looks like. The selected item (inside the gray field) is ok, but the tabulator width of all items in the combobox dropdown menu is too large:

    alt text

    Is there any way to change the tabulator width in the combobox dropdown menu? If not how to achieve the wished alignment? How is that done?

    Regards,
    mireiner

    Christian EhrlicherC 1 Reply Last reply
    0
    • M mireiner

      Hello,

      in a QComboBox each item string consists of two parts. And the second string part should be aligned to the second string parts of all following combobox rows.

      I tried to achieve this using a tabulator (\t) in the item strings. But the tabulator width is too large and I couldn't find a way to change it:

      #include <QApplication>
      #include <QWidget>
      #include <QComboBox>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          QWidget w;
      
          QComboBox combo1(&w);
          combo1.setStyleSheet("QComboBox { combobox-popup: 0; }");
          combo1.setFont(QFont("Roboto",10));
          combo1.setGeometry(20,20,300,25);
      
          QString string1("A\t:Something");
          combo1.addItem(string1);
      
          QString string2("DNX\t:Something");
          combo1.addItem(string2);
      
          QString string3("B\t:Something");
          combo1.addItem(string3);
      
          QString string4("KLQ\t:Something");
          combo1.addItem(string4);
      
          QString string5("GT\t:Something");
          combo1.addItem(string5);
      
          QString string6("F\t:Something");
          combo1.addItem(string6);
      
          w.show();
          w.resize(340, 200);
          return a.exec();
      }
      

      This is how it looks like. The selected item (inside the gray field) is ok, but the tabulator width of all items in the combobox dropdown menu is too large:

      alt text

      Is there any way to change the tabulator width in the combobox dropdown menu? If not how to achieve the wished alignment? How is that done?

      Regards,
      mireiner

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @mireiner said in QComboBox how to change tab stop width?:

      Is there any way to change the tabulator width in the combobox dropdown menu?

      It's not

      If not how to achieve the wished alignment?

      Write your own QStyledItemDelegate and to the alignment by your own.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      4
      • M Offline
        M Offline
        mireiner
        wrote on last edited by
        #3

        Hello Christian,

        I'll will look into the QStyledItemDelegate and see how it works.

        Thank you for the help!

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved