how to resize Qmainwindow with Qwidget ?
I have trayicon on Qdialog, also I have a webview on Qmainwindow. I want to do that a web page run like tray. The codes run perfectly but i have a problem with the window size. when I maximize the page on tray, the web page is smaller than qwidget.
Code:
//main.cpp
#include "window.h" //the object inherited by Qdialog
#include "mainwindow.h" //the object inherited by Qmainwindow
int main(int argc, char *argv[])
{
Window box;
MainWindow window;
window.setParent(&box);
return app.exec();
}
//window.cpp
Window::Window()
{
createActions();
createTrayIcon();
setIcon();
/*..*/
trayIcon->show();
setWindowTitle(tr("Blog Search"));
resize(600, 600);
}
MainWindow::MainWindow()
{
qsrand((uint)time.msec());
int randomValue = qrand() % 999;
view = new QWebView(this);
QUrl url
= QUrl::fromEncoded("http://blogsearch.google.com/blogsearch?hl=tr&ie=UTF-8&q=C%2B%2B&&output=rss");
url.addQueryItem("num", "1");
url.
addQueryItem("start" ,
QString::number(randomValue
));
view->load(url);
/* ...... */
setCentralWidget(view);
}
/*
all the functions here
*/
some of the codes above.
Can you help me about what can I do for resize the mainwindow ?
Re: how to resize Qmainwindow with Qwidget ?
You have to put MainWindow into the layout of Window.
Re: how to resize Qmainwindow with Qwidget ?
I'm new in Qt. So can you explain more ? If I add a new window to apllication am I alway use a layout ?
Re: how to resize Qmainwindow with Qwidget ?
Since I don't understand your design exactely, please provide a minimal compilable example reproducing your problem.
Re: how to resize Qmainwindow with Qwidget ?
Code:
//main.cpp
#include <QtGui>
#include "window.h"
#include "mainwindow.h"
int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(systray);
Window box;
MainWindow window;
window.setParent(&box);
return app.exec();
}
//mainwindow.cpp
#include <QtGui>
class QWebView;
//! [1]
{
Q_OBJECT
public:
MainWindow();
private:
QWebView *view;
};
//window.h
#ifndef WINDOW_H
#define WINDOW_H
#include <QDialog>
#include <QSystemTrayIcon>
#include <QMenu>
#include <QLineEdit>
#include <QTextEdit>
{
Q_OBJECT
public:
Window();
private slots:
void setIcon();
void showMessage();
private:
void createActions();
void createTrayIcon();
};
#endif
//window.cpp
#include <QtGui>
#include <QtWebKit>
#include <QTime>
#include "window.h"
#include "mainwindow.h"
Window::Window()
{
createActions();
createTrayIcon();
setIcon();
trayIcon->show();
setWindowTitle(tr("Blog Search"));
resize(600, 600);
}
MainWindow::MainWindow()
{
file.setFileName(":/jquery.min.js");
jQuery = file.readAll();
file.close();
QNetworkProxyFactory::setUseSystemConfiguration(true);
qsrand((uint)time.msec());
int randomValue = qrand() % 999;
view = new QWebView(this);
QUrl url
= QUrl::fromEncoded("http://blogsearch.google.com/blogsearch?hl=tr&ie=UTF-8&q=C%2B%2B&&output=rss");
url.addQueryItem("num", "1");
url.
addQueryItem("start" ,
QString::number(randomValue
));
view->load(url);
setCentralWidget(view);
}
void Window::setIcon()
{
icon.
addPixmap(QPixmap(":/images/heart.svg"));
trayIcon->setIcon(icon);
trayIcon->setVisible(true);
setWindowIcon(icon);
}
{
switch (reason) {
break;
showNormal();
break;
showMessage();
break;
default:
;
}
}
void Window::showMessage()
{
titleEdit
= new QLineEdit(tr
("Blog Search"));
bodyEdit->setPlainText(trUtf8("Blog okumak icin sag click + Maximize\n yapmaniz yeterli"));
trayIcon
->showMessage
(titleEdit
->text
(), bodyEdit
->toPlainText
(),
QSystemTrayIcon::Information,
1000);
}
void Window::createActions()
{
minimizeAction
= new QAction(tr
("Mi&nimize"),
this);
connect(minimizeAction, SIGNAL(triggered()), this, SLOT(hide()));
maximizeAction
= new QAction(tr
("Ma&ximize"),
this);
connect(maximizeAction, SIGNAL(triggered()), this, SLOT(showMaximized()));
restoreAction
= new QAction(tr
("&Restore"),
this);
connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal()));
quitAction
= new QAction(tr
("&Quit"),
this);
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
}
void Window::createTrayIcon()
{
trayIconMenu
= new QMenu(this);
trayIconMenu->addAction(minimizeAction);
trayIconMenu->addAction(maximizeAction);
trayIconMenu->addAction(restoreAction);
trayIconMenu->addSeparator();
trayIconMenu->addAction(quitAction);
trayIcon->setContextMenu(trayIconMenu);
}
Re: how to resize Qmainwindow with Qwidget ?
Ok, you don't use layouts at all. Please read the doc about layouts: http://doc.trolltech.com/4.6/layout.html. Also I don't see a reason why you have a widget and a main window. You can put all into one! If you need different widgets inside a main window see QStackedWidget.
Re: how to resize Qmainwindow with Qwidget ?
Quote:
Originally Posted by
Lykurg
Ok, you don't use layouts at all. Please read the doc about layouts:
http://doc.trolltech.com/4.6/layout.html. Also I don't see a reason why you have a widget and a main window. You can put all into one! If you need different widgets inside a main window see
QStackedWidget.
but I have to use QToolBar, so when I put all them in one widget an error occured. for example; addToolBar was not declared in this scope. That's why I prefer to use Qmainwindow.
Re: how to resize Qmainwindow with Qwidget ?
Of course you should use QMainWindow, but why you then make another window called window? Should there be two windows?
Re: how to resize Qmainwindow with Qwidget ?
Quote:
Originally Posted by
Lykurg
Of course you should use QMainWindow, but why you then make another window called window? Should there be two windows?
No, it should'nt. Firstly I tried it but can't do it one window then I did it like that. Now there is only one problem that; size of the window.
If it will be easier to do it in one window okay then I try it to do in one window. :)
Re: how to resize Qmainwindow with Qwidget ?
I'm a new QT. have same issue with @zeynepb.bil
https://i.imgur.com/WEBkimQ.png
Can you help me?
Re: how to resize Qmainwindow with Qwidget ?
Put everything that is inside the QWidget "centralWidget" inside a layout of some sort. Look at the Qt Layout examples and follow the link on that page to Layout Management for the explanation of how it all works.