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. A stange problem in QGroupBox

A stange problem in QGroupBox

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 853 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.
  • LimerL Offline
    LimerL Offline
    Limer
    wrote on last edited by Limer
    #1
    // mainwindow.cpp
    
    QWidget* widget = new QWidget;
        QComboBox* box = new QComboBox;
        box->addItem("a");
        box->addItem("b");
        box->addItem("c");
        QVBoxLayout* layout = new QVBoxLayout;
        layout->addWidget(box);
        widget->setLayout(layout);
        setCentralWidget(widget);
    
    // main.cpp
    
    qApp->setStyleSheet("QWidget{font-family: 'Microsoft YaHei UI'; font-size: 15px;}"
                            "QComboBox{font-size: 13px;}");
    

    You just create a new widget project, and add the upper codes, you will get the following result,

    0_1543922860920_2.gif

    The items in groupbox overlaped with each other.

    Why is that? Could someone tell me the WHY and HOW? Thanks in advance.

    (PS: windows10 + qt 5.10.1 + qt-creator 4.5.1 + msvc2015 x86)

    jsulmJ 1 Reply Last reply
    0
    • LimerL Limer
      // mainwindow.cpp
      
      QWidget* widget = new QWidget;
          QComboBox* box = new QComboBox;
          box->addItem("a");
          box->addItem("b");
          box->addItem("c");
          QVBoxLayout* layout = new QVBoxLayout;
          layout->addWidget(box);
          widget->setLayout(layout);
          setCentralWidget(widget);
      
      // main.cpp
      
      qApp->setStyleSheet("QWidget{font-family: 'Microsoft YaHei UI'; font-size: 15px;}"
                              "QComboBox{font-size: 13px;}");
      

      You just create a new widget project, and add the upper codes, you will get the following result,

      0_1543922860920_2.gif

      The items in groupbox overlaped with each other.

      Why is that? Could someone tell me the WHY and HOW? Thanks in advance.

      (PS: windows10 + qt 5.10.1 + qt-creator 4.5.1 + msvc2015 x86)

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Limer Is it same without setStyleSheet?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      LimerL 1 Reply Last reply
      0
      • jsulmJ jsulm

        @Limer Is it same without setStyleSheet?

        LimerL Offline
        LimerL Offline
        Limer
        wrote on last edited by
        #3

        @jsulm No, if I removed the qss codes, it will get normal.

        jsulmJ 1 Reply Last reply
        0
        • LimerL Limer

          @jsulm No, if I removed the qss codes, it will get normal.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Limer I'm not an stylesheet expert, but to me it looks like you're overwriting the stylesheet for QComboBox instead of only changing the font.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          LimerL 1 Reply Last reply
          0
          • jsulmJ jsulm

            @Limer I'm not an stylesheet expert, but to me it looks like you're overwriting the stylesheet for QComboBox instead of only changing the font.

            LimerL Offline
            LimerL Offline
            Limer
            wrote on last edited by Limer
            #5

            @jsulm If I removed the qroupbox's qss codes but reserved the qwidget's qss , the result is still like that.

            jsulmJ 1 Reply Last reply
            0
            • LimerL Limer

              @jsulm If I removed the qroupbox's qss codes but reserved the qwidget's qss , the result is still like that.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Limer What I mean is: if you set the stylesheet you overwrite what was set before and probably there are some other stylesheet properties which define the look of the widgets which are then lost.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              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