I'm using QRubberband and it's working fine inside of my program, but I want to get the coordinates outside of my program. In other words, using it outside of my program while it's running!
To be more clear, I'm using a Qt class called QRubberband which helps you select a rectangle or line "clicking and then drag." Everything is working when I use it inside of my project space, but I can't use it outside - for example when I activate it I should be able to select from maybe this site, or anywhere in the screen not just my program.
The QRubberBand man page says:
If you pass a parent to QRubberBand's constructor, the rubber band
will display only inside its parent, but stays on top of other child
widgets. If no parent is passed, QRubberBand will act as a top-level
widget.
So at the risk of asking the obvious... are you passing in NULL as the second argument to the QRubberBand constructor?
Related
I have an application with a QMainWindow that should ideally have a QGLWidget centered on it, with spaces left around the outside for toolbars and other top/side widgets.
Unfortunately, no matter what size or geometry the QGLWidget is set to, it appears enormous and takes up the entire main window!
Basically, the setup is as follows: CreateWindow() is called in main(), which constructs the main window and calls a function Init(), which constructs the GLWidget. So, within Init(), which is a member of my adapted main window class, I essentially have:
GLScene = new MyQGLWidget(this);
setCentralWidget(GLScene);
Now, to make the GLScene conform to its desired size and position, I first tried setting its geometry within the GLWidget (a.k.a. my class derived directly from GLWidget) constructor:
MyQGLWidget::MyQGLWidget(QWidget* parent){
....
setGeometry(210, 40, 600, 400); //the main window is of course bigger and should fit this nicely
....
}
This, however, didn't work at all and still made it take up the entire main window. Instead, I tried putting the setGeometry call into Init(). I tried it both right before and right after setCentralWidget(); neither option worked. Nor did flat-out removing the setCentralWidget call (in fact, this made the GLWidget disappear).
Since this clearly isn't working properly, what is the correct way to scale the GLWidget? Or is it just a matter of how things are ordered that I need to look into more deeply?
You need to add a layout to it. I have exactly the same thing ( a widget derived from QGLWidget) whose parent calls the resize function. This solved all my issues and made it to where I can change its size at runtime.
I am writing an application using Qt and would like to have a "Metro Style" interface. Everything is finished except I don't know how to make the widget appear and disappear. For instance, in WPF you can animate (UIElement.RenderTransform).(TranslateTransform.Y) so that Y becomes zero or negative. How can I move the QWidget in a QGridLayout so that it can hide?
Example:
After doing some research I figured out a way to do this. Instead of letting Qt do the layout I simply handled it myself via move and set width/height functions. Overriding resizeEvent made it so I could update the values in case the window was resized. Additionally I used setMask to ensure that the widget did not leak over to unwanted locations in the UI.
My question is, if it is possible to display buttons on an opengl-window. As you can see on the picture I have created in the main window two smaller ones. The right grey corner is designated for the buttons(marked with a red rectangle). This I created before using Qt. Now I see that Qt is always creating the buttons at the border of the window. Is it possible to place my buttons in this red rectangle?
I am using a mac.
Yes. In code, set the containing widget as the parent of the contained widget in its constructor or use setParent() after it has already been constructed.
I am working in Qt in my program. I have a widget window and I have placed a button and a list box in it. Then I have made a class called myplot which graph plotting is done. Then in my button event handler I have called the object of myplot
myplot * p1 = new myplot(session,session ,24, "session"); // send arrays in argument containing the data to be plot
p1->show();
myplot * p2 = new myplot(payload,payload ,24, "payload"); // send arrays in argument containing the data to be plot
p2->show();
It is working fine as my graph appear in new window, but what I want is that graphs should appear in my mainwidget window.
What I did next was to remove the title bar of my graphs window I wrote this
Qt Code:
p1->setWindowFlags(Qt::FramelessWindowHint);
p2->setWindowFlags(Qt::FramelessWindowHint);
Now
1) what should I do to place and append the graphs window in my main window? Also when I close main window my graph window should close.
2) when I select an other value from the list box and click button my old graph disappear and new should appear
i drag and droped a verticlalayout then write
ui->verticalLayout->addChildWidget(p1);
but got an error
/usr/include/qt4/QtGui/qlayout.h:191: error: ‘void QLayout::addChildWidget(QWidget*)’ is protected
then i draaged and droped a scrollarea and wrote
myplot * p1 = new myplot(session,session ,24, "session");
p1->setWindowFlags(Qt::FramelessWindowHint);
ui->scrollArea->addScrollBarWidget(p1,0);
p1->show();
my graphs stopped appearing kindly guide me am i doing it wrong or what the right way
Apparently, myplot is a childclass of QWidget. So you can just define a layout on your main window (e.g. using QHBoxLayout), and add those two widgets to it. This will cause them to be drawn inside the mainwindow. Also make sure that you pass the main window as the QWidget parent of the plots.
For replacing the plots, you can either remove the old plots from the layout and add new ones. But I would prefer to make the plots members of your main window and include some update method that would redraw with the new data
When you call show on widgets with no parent like that, it automatically gets wrapped in a window. What you should do is create one widget and add the graphs to it's layout. See QMainWindow examples, and section about dock widgets if that's what you want.
Basically you don't need to worry about the window they are appearing in, it is only appearing because they have no other parent.
What you need to do is to specify a parent widget when you construct them.
(This answer is based on the assumption that your plots are also QWidgets, if you could mention what class they actually are and perhaps link to the documentation it would really help us to answer you.)
I am trying to create an app in Qt/C++ with Qt4.5 and want the any active windows to change opacity on a mouseover event...
As i understand it, there is no explicit mouseover event in Qt.
However, I got rudimentary functioning by reimplementing QWidget's mousemoveevent() in the class that declares my mainwindow. But the mainwindow's mousemoveevent is not called whenever the mouse travels over any of the group boxes i have created in there (understandbly since QGroupbox has its own reimplementation of mousemoveevent).
So as a cheap work around, I am still using the mousemoveevent of my mainwindow but a query the global mouse position and based on the (x,y) position of the mainwindow (obtained through ->pos()) and the window size (-> size -> rHeight and rWidth), I check if the mouse is within the bounds of the area of the mainwindow and change the opacity thus.
This has had very limited success. The right border works fine, the the left changes opacity 4 pixels early. The top does not work (presumably because the mouse goes through the menubar and title bar) and the bottom changes way too early.
I thought of creating an empty container QWidget class and then place all the rest in there, but i felt that it would still not solve the big issue of the base widget not receiving the mousemoveevent if it has already been implemented in a child widget.
Please suggest any corrections/errors I have made in my method or any alternate methods to achieve this.
p.s. I doubt this matters, but I am working Qt Creator IDE, not Qt integration into VS2008 (it's the same classes anyways - different compiler though, mingw)
Installing event filters for each of your child widgets might do the trick. This will allow your main window to receive child events such as the ones from you group boxes. You can find example code here.
You may be interested in Event filters. QObject proves a way to intercept all events zipping around your application.
http://doc.trolltech.com/4.5/eventsandfilters.html#event-filters
If I understand what you are attempting to do, I would reimplement the widget's enterEvent() and leaveEvent(). The mouse enter event would trigger the fade-in and the leaveEvent would trigger the fade-out.
EDIT: After re-reading several times, I'm still not sure what you are trying to accomplish. Sorry if my suggestion doesn't help. :-)