根据QMainWindow的大小

时间:2016-03-30 12:51:20

标签: c++ qt webview qwidget

我是QT的新手。我为Windows制作了一个包含QWebViewQMessageBox的应用程序。我想根据QMainwindow的大小调整这两个大小。例如,如果主窗口的大小为300*200,则QWebViewQMessageBox的大小应相同。另外,我希望能够在运行我的应用程序时调整它的大小。

有人可以告诉我该怎么做吗?

1 个答案:

答案 0 :(得分:0)

首先,我认为您应该制作$ make Scanning dependencies of target cpp_factory [ 11%] Building CXX object CMakeFiles/cpp_factory.dir/libraries/src/FileLister.cpp.o In file included from /home/ub1404/Application/cpp_factory/libraries/src/FileLister.cpp:5:0: /home/ub1404/Application/cpp_factory/libraries/include/cpp_factory/files/FileLister.h: In constructor ‘FilesList::FilesList(const string&, const string&, const FileSorter&)’: /home/ub1404/Application/cpp_factory/libraries/include/cpp_factory/files/FileLister.h:109:57: error: no matching function for call to ‘sort(std::vector<boost::filesystem::path>::iterator, std::vector<boost::filesystem::path>::iterator, const FileSorter&)’ std::sort(this->begin(), this->end(), fileSorter); ^ /home/ub1404/Application/cpp_factory/libraries/include/cpp_factory/files/FileLister.h:109:57: note: candidates are: In file included from /usr/include/c++/4.8/algorithm:62:0, from /home/ub1404/Application/cpp_factory/libraries/include/cpp_factory/files/FileLister.h:11, from /home/ub1404/Application/cpp_factory/libraries/src/FileLister.cpp:5: /usr/include/c++/4.8/bits/stl_algo.h:5447:5: note: template<class _RAIter> void std::sort(_RAIter, _RAIter) sort(_RandomAccessIterator __first, _RandomAccessIterator __last) ^ /usr/include/c++/4.8/bits/stl_algo.h:5447:5: note: template argument deduction/substitution failed: In file included from /home/ub1404/Application/cpp_factory/libraries/src/FileLister.cpp:5:0: /home/ub1404/Application/cpp_factory/libraries/include/cpp_factory/files/FileLister.h:109:57: note: candidate expects 2 arguments, 3 provided std::sort(this->begin(), this->end(), fileSorter); ^ In file included from /usr/include/c++/4.8/algorithm:62:0, from /home/ub1404/Application/cpp_factory/libraries/include/cpp_factory/files/FileLister.h:11, from /home/ub1404/Application/cpp_factory/libraries/src/FileLister.cpp:5: /usr/include/c++/4.8/bits/stl_algo.h:5483:5: note: template<class _RAIter, class _Compare> void std::sort(_RAIter, _RAIter, _Compare) sort(_RandomAccessIterator __first, _RandomAccessIterator __last, ^ /usr/include/c++/4.8/bits/stl_algo.h:5483:5: note: template argument deduction/substitution failed: /usr/include/c++/4.8/bits/stl_algo.h: In substitution of ‘template<class _RAIter, class _Compare> void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<boost::filesystem::path*, std::vector<boost::filesystem::path> >; _Compare = FileSorter]’: /home/ub1404/Application/cpp_factory/libraries/include/cpp_factory/files/FileLister.h:109:57: required from here /usr/include/c++/4.8/bits/stl_algo.h:5483:5: error: cannot allocate an object of abstract type ‘FileSorter’ In file included from /home/ub1404/Application/cpp_factory/libraries/src/FileLister.cpp:5:0: /home/ub1404/Application/cpp_factory/libraries/include/cpp_factory/files/FileLister.h:49:8: note: because the following virtual functions are pure within ‘FileSorter’: struct FileSorter{ ^ /home/ub1404/Application/cpp_factory/libraries/include/cpp_factory/files/FileLister.h:51:18: note: virtual bool FileSorter::operator()(const boost::filesystem::path&, const boost::filesystem::path&) const virtual bool operator()(const boost::filesystem::path& p1, const boost::filesystem::path& p2) const =0; ^ make[2]: *** [CMakeFiles/cpp_factory.dir/libraries/src/FileLister.cpp.o] Error 1 make[1]: *** [CMakeFiles/cpp_factory.dir/all] Error 2 make: *** [all] Error 2 的{​​{1}}和QMessageBox个小部件。QWebView。您应该在QMainWindow文件中输入以下内容:

.cpp

包含MyApp::MyApp(QWidget *parent) : QMainWindow(parent) { mView = new QWebView(this); mMessageBox = new QMessageBox(this); // some other code } 文件的mViewmMessageBox个私有元素。

对于大小,如果您没有指定任何内容,您应该能够根据需要调整大小。或者,如果您想尝试固定尺寸,只需添加此行而不是.h

//some other code