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. Position of a Qt Combobox dropdown
Forum Updated to NodeBB v4.3 + New Features

Position of a Qt Combobox dropdown

Scheduled Pinned Locked Moved Unsolved General and Desktop
qcomboboxqlistview
10 Posts 3 Posters 8.7k 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.
  • S Offline
    S Offline
    sunil.nair
    wrote on last edited by sunil.nair
    #1

    My problem is that the anything I do in the QAbstractItemView is not being reflected in the combobox? I can't find out why?

        //set max visible to 3 items
        setMaxVisibleItems(3);
        //Do not insert item to combobox on pressing enter
        setInsertPolicy(QComboBox::NoInsert);
        //Set its size policy to [fixed,fixed]
        setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
        //Set height and width
        setFixedSize(133,35);
        //We change the default item delegate to styled item delegate so we can modify using stylesheets
        QStyledItemDelegate* itemDelegate = new QStyledItemDelegate();
        setItemDelegate(itemDelegate);
    
        //customize the combobox using stylesheet. QAbstractItemView is the popup view when the down arrow is clicked
        setStyleSheet("QComboBox {\
                      border: 1px solid rgb(228,228,228);\
                          border-radius: 2px;\
                      font-family: \"Helvetica Neue Med\";\
                      font-size: 11px;padding-left:25px;\
                  }\
                  \
                  QComboBox:!editable {\
                      color: rgb(72,72,72);\
                      background:  rgb(228,228,228);\
                  }\
                  \
                  QComboBox::drop-down {\
                      background:  rgb(228,228,228);\
                      width: 45px;\
                  }\
                  \
                  QComboBox::down-arrow {\
                      subcontrol-position: left;\
                      image: url(:/images/Arrow_off.png);\
                  }\
                  QComboBox::down-arrow:on { \
                      image: url(:/images/Arrow_on.png);\
                  }\
                    \
                  QComboBox QAbstractItemView {\
                      color: rgb(72,72,72);\
                      background: rgb(228,228,228);\
                      min-width:233px;\
                  }\
                  \
                  QComboBox QAbstractItemView::item {\
                      min-height: 27px;max-height:27px;\
                      border-bottom: 0px solid rgb(40,40,40);\
                      padding-right: 25px;\
                  }\
                  \
                  QComboBox QAbstractItemView::item:selected {\
                      background: rgb(72,72,72);\
                      color:rgb(28,228,228);\
                      padding-right: 25px;\
                  }\
                  ");
    
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      MaxDevI
      wrote on last edited by MaxDevI
      #2

      Hi @sunil-nair, can you please post the code where you make the QComboBox, and any related style changes?

      Also, maybe you can try setting a padding for the QComboBox?

      QComboBox {
              padding: 1px 0px 1px 3px;
      }
      
      1 Reply Last reply
      0
      • S Offline
        S Offline
        sunil.nair
        wrote on last edited by sunil.nair
        #3
        This post is deleted!
        S 1 Reply Last reply
        0
        • S sunil.nair

          This post is deleted!

          S Offline
          S Offline
          sunil.nair
          wrote on last edited by
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • p3c0P Offline
            p3c0P Offline
            p3c0
            Moderators
            wrote on last edited by
            #5

            @sunil-nair Does it work if you donot provide the QStyledItemDelegate ? What was the purpose of using it if you haven't subclassed it ?

            157

            S 1 Reply Last reply
            0
            • p3c0P p3c0

              @sunil-nair Does it work if you donot provide the QStyledItemDelegate ? What was the purpose of using it if you haven't subclassed it ?

              S Offline
              S Offline
              sunil.nair
              wrote on last edited by sunil.nair
              #6

              @p3c0 No if I dont use StyledItemdelegate, the entire list becomes non stylable. I have updated the mainquestion by inserting the code.

              1 Reply Last reply
              0
              • p3c0P Offline
                p3c0P Offline
                p3c0
                Moderators
                wrote on last edited by
                #7

                @sunil-nair I think if you want to use it QStyledItemDelegate you need to subclass it then re-implement paint then initStyleOption to initialize its defaults.

                void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
                  ...
                  ...
                  initStyleOption(&option, index);
                  ...
                  ...
                }
                

                157

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  sunil.nair
                  wrote on last edited by sunil.nair
                  #8

                  Thanks but I guess I figured something. If the QCombobox is non editable it cannot be styled (i am not able to ) using QAbstractItemView. Any styling on it requires a QListView object and we need to setView(QListView)

                  void SteuerQComboBox::showPopup() {
                  QComboBox::showPopup();
                  QWidget popup = this->findChild<QFrame>();
                  popup->move(popup->x(),popup->y()-this->height()-popup->height());
                  }

                  We can now position it anywhere we want. Please refer: http://stackoverflow.com/questions/10057140/how-to-make-qcombobox-popup-upwards

                  1 Reply Last reply
                  1
                  • p3c0P Offline
                    p3c0P Offline
                    p3c0
                    Moderators
                    wrote on last edited by
                    #9

                    @sunil-nair So what was the question exactly ? Make the popup pop upwards ?

                    157

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      sunil.nair
                      wrote on last edited by
                      #10

                      I apologise for the delay in response. The question was to make sure that the combobox always pops up in a given direction or position.

                      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