久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

QScrollArea 缺少滾動條

QScrollArea missing Scrollbar(QScrollArea 缺少滾動條)
本文介紹了QScrollArea 缺少滾動條的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我認為這是與以下相同的問題:QScrollArea resizing QWidget

I think it is the same problem as : QScrollArea resizing QWidget

但沒有解決方案.所以讓我揭露這個問題.

but there are not solution. so let me expose the problem.

  • 測試2繼承自QWidget:
    • 組成:
      • QSpinBox 的向量
      • QScrollArea
      • QVBoxLayout
      • 沒有滾動條
      • [FIXED] 滾動條的內部被縮小以適應如此小的空間,無法讀取任何內容(可以在執行期間調整窗口大小,這將導致內部變大且可讀,但不會出現滾動條)

      我認為問題來自單一來源 :: 尺寸提示和布局 (http://qt-project.org/doc/qt-5.1/qtwidgets/qscrollarea.html#details)

      I Think problems come from a single source :: Size Hints and Layouts (http://qt-project.org/doc/qt-5.1/qtwidgets/qscrollarea.html#details)

      第二個問題(縮小的widget)可以通過設置"c->setSizeConstraint(QLayout::SetMinimumSize);"來解決

      The second problem (shrinked widget) can be solved by setting "c->setSizeConstraint(QLayout::SetMinimumSize);"

      我目前正在尋找缺少滾動條的解決方案

      I am currently seeking a solution for the missing scrollbar

      這是顯示我的問題的代碼:

      here is a code showing my problem :

      <c++>
      #include <QWidget>
      #include <QScrollArea>
      #include <QVBoxLayout>
      #include <QSpinBox>
      
      class test2 : public QWidget
      {
              Q_OBJECT
          public:
              test2(QWidget *parent = 0) :QWidget(parent)
              {
                  b = new QScrollArea(this);
                  c = new QVBoxLayout;
      
                  for (int i = 0; i < 10; i++)
                  {
                      a.push_back(new QSpinBox());
                      c->addWidget(a[i]);
                  }
      
                  c->setSizeConstraint(QLayout::SetMinimumSize);
                  b->setLayout(c);
                  b->resize(200, 200);
              }
      
              ~test2()
              {
                  for (int i = 0; i < 10; i++)
                      delete a[i];
              }
      
          protected:
      
              QVector<QSpinBox*> a;
              QScrollArea* b;
              QVBoxLayout* c;
      
      };
      
      
      int main(int argc, char *argv[])
      {
          ///*
          QApplication app(argc, argv);
      
          test2 a;
      
          a.show();
      
          return app.exec();//*/
      }
      

      編輯 :: 在這里找到了解決方案:http://qt-project.org/forums/viewthread/295

      EDIT :: found a Solution here: http://qt-project.org/forums/viewthread/295

      如果你不想在這里閱讀大量無用的代碼,他做了什么 ::他扭曲了小部件內的布局

      if you don't want to read huge amount of useless code here what he has done :: he warped the layout inside a widget

      解決方案::從ScrollBar繼承Object <- Widget <- Layout

      Solution :: inherit the Object from ScrollBar <- Widget <- Layout

      代替小部件 <- ScrollBar <- Layout

      instead of widget <- ScrollBar <- Layout

      但它的解決方法并不是真正的解決方案......我要嘗試我給出的例子.

      but it a work around not really a solution... I going to try on the example I gave.

      它有效.有沒有人有更好的解決方案??

      it works. Does anyone have a better solution ??

      推薦答案

      您不想在滾動區域本身上設置布局.您引用的答案源于對此的誤解.

      You do not want to set the layout on the scroll area itself. The answer you cite stems from misunderstanding this.

      1. 您需要在滾動區域內有一個小部件,然后使用 QScrollArea::setWidget 將該小部件傳遞到該區域.如果滾動區域內只有一個沒有子項的小部件,那么您不需要額外的布局.

      1. You need to have a widget within a scrollarea, and you pass that widget to the area using QScrollArea::setWidget. If all you have inside the scroll area is one widget with no children, then you don't need additional layout.

      您無需手動跟蹤布局擁有的小部件.刪除具有布局的小部件后,它們將自動刪除.

      You do not need to manually keep track of widgets that are owned by a layout. They'll be deleted automatically once the widget that has the layout is deleted.

      QScrollArea 小部件未布置在其封閉小部件中.

      The QScrollArea widget is not laid out within its enclosing widget.

      以下是如何操作的示例:

      Below is a working example of how to do it:

      // https://github.com/KubaO/stackoverflown/tree/master/questions/scroll-18703286
      #include <QScrollArea>
      #include <QVBoxLayout>
      #include <QSpinBox>
      #include <QApplication>
      
      class Window : public QWidget
      {
         QVBoxLayout m_layout{this};
         QScrollArea m_area;
         QWidget m_contents;
         QVBoxLayout m_contentsLayout{&m_contents};
         QSpinBox m_spinBoxes[10];
      public:
         Window(QWidget *parent = {}) : QWidget(parent) {
            m_layout.addWidget(&m_area);
            m_area.setWidget(&m_contents);
            for (auto & spinbox : m_spinBoxes)
               m_contentsLayout.addWidget(&spinbox);
            m_contentsLayout.setSizeConstraint(QLayout::SetMinimumSize);
         }
      };
      
      int main(int argc, char *argv[])
      {
         QApplication app(argc, argv);
         Window w;
         w.show();
         return app.exec();
      }
      

      這篇關于QScrollArea 缺少滾動條的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

      【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數據?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環: for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環?)
Reusing thread in loop c++(在循環 C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環形?)
主站蜘蛛池模板: 密室大逃脱第六季大神版在线观看 | 亚洲一区二区三区四区av | 91精品国产手机 | 精品欧美一区二区精品久久久 | 中文字幕第二区 | 一区二区三区精品在线 | 狠狠亚洲| 亚洲一区视频在线 | 成人影院在线 | 久久99这里只有精品 | 亚洲小视频在线播放 | 国产一区二区黑人欧美xxxx | 欧美激情久久久 | 日本午夜在线视频 | 国产精品免费播放 | 成人性视频在线 | 精品一二区 | 国产精品久久久久久久久免费软件 | 日韩欧美黄色 | 成人免费精品视频 | 欧美色专区 | 国产精品精品 | 国产中文视频 | 亚洲精品久久久久久久久久久 | 人人看人人草 | 欧美成人h版在线观看 | 亚洲视频在线观看免费 | 亚洲欧美综合精品久久成人 | 午夜精品久久 | 午夜欧美a级理论片915影院 | 日韩一二区 | 国产一区二区三区在线 | 成人免费视频在线观看 | 黄色一级大片在线免费看产 | 国产精品视频网站 | 逼逼视频| 欧美一级黄色免费看 | 午夜寂寞影院在线观看 | 欧美日韩国产在线观看 | av一区二区在线观看 | 91天堂|