久久久久久久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] 滾動條的內(nèi)部被縮小以適應如此小的空間,無法讀取任何內(nèi)容(可以在執(zhí)行期間調(diào)整窗口大小,這將導致內(nèi)部變大且可讀,但不會出現(xiàn)滾動條)

      我認為問題來自單一來源 :: 尺寸提示和布局 (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

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

      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 ??

      推薦答案

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

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

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

      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模板網(wǎng)!

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

相關文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數(shù)據(jù)?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環(huán): for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環(huán)?)
Reusing thread in loop c++(在循環(huán) C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環(huán)形?)
主站蜘蛛池模板: 麻豆久久久久 | 欧美国产精品一区二区 | 蜜桃视频一区二区三区 | 日本精品一区二区三区视频 | 国产精品久久久久无码av | 精品国产欧美一区二区 | 久久福利电影 | 特黄特色大片免费视频观看 | av在线一区二区 | 天天拍天天射 | 久久精品视频免费观看 | 国产高清精品在线 | 美女天天操 | 国产在线精品一区二区三区 | 毛片com | 久久久精彩视频 | 97成人精品 | 97人人澡人人爽91综合色 | 日本不卡免费新一二三区 | 高清视频一区二区三区 | 又爽又黄axxx片免费观看 | 男女羞羞视频在线观看 | 欧美视频精品 | 在线视频国产一区 | 亚洲综合一区二区三区 | av手机在线播放 | 午夜免费看视频 | 秋霞电影一区二区 | 亚洲一区二区在线视频 | 天天干天天操天天射 | 亚洲女人天堂成人av在线 | 亚洲成av人片在线观看无码 | 精品一区二区在线看 | 午夜日韩| 91久久国产综合久久 | 日韩成人免费av | 一本色道久久综合亚洲精品高清 | 一级毛片在线视频 | 欧美男人天堂 | 亚洲国产精品久久久久 | 亚洲麻豆 |