maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Applications (https://talk.maemo.org/forumdisplay.php?f=41)
-   -   How do I make a scrollable gui with QtCreator? (https://talk.maemo.org/showthread.php?t=72766)

azkay 2011-05-04 01:36

How do I make a scrollable gui with QtCreator?
 
Ive looked through;
http://wiki.maemo.org/Qt4_Hildon_Leg...etic_scrolling
http://doc.qt.nokia.com/qt-maemo-4.6...tml#setEnabled
http://doc.qt.nokia.com/qt-maemo-4.6...-textedit.html

I still cant get a scrollable gui working.
Basically, im trying to make a QScrollArea and be able to, well, kinetic scrolling.

I plan on have lots of text labels and images, I am wanting to be able to scroll down the GUI to be able to read them.

Anyone got an example?

gionni88 2011-05-04 07:03

Re: How do I make a scrollable gui with QtCreator?
 
If you're using QtDesigner, right click inside the QScrollArea and pick a layout, than you can start adding your labels.

If the scroll area is a lot bigger, than expand your main window to the bottom and make a QWidget where you place all your objects, than in the MainWindow constructor set this widget inside the scrollArea: ui->scrollArea->setWidget(ui->widget);

azkay 2011-05-04 11:05

Re: How do I make a scrollable gui with QtCreator?
 
Thanks, I dont know how I missed that.

pichlo 2014-07-16 20:51

Re: How do I make a scrollable gui with QtCreator?
 
Is reviving a 3yo thread better or worse than creating a new one? :)

Anyway, I have a QScrollArea that covers most of the screen. Inside it, I have a widget of type Preview, derived from QGLWidget.

I also have zoom buttons. Zoom affects the horizontal size only, the vertical dimension is fixed. The problem is that zooming in more than two times segfaults the program.

Here is the relevant bit where it segfaults:
Code:

void Preview::paintGL ()
{
  QPainter painter(this);
  painter.setRenderHint(QPainter::Antialiasing, true);

  const int w = width();
  const int h = height();

  // Paint the background
  painter.fillRect(0, 0, w, h, Qt::white);

  // ... a few dozen more lines ...

  painter.end();
}

It crashes on the painter.fillRect line, as verified by sticking qDebug before and after. Values of w and h were:

w=668, h=416, OK (starting point)
w=1002, h=416, OK (zoom in x1)
w=1503, h=416, OK (zoom in x2)
w=2254, h=416, crash!

What is going on? Can the device not handle painting areas of that size? (Code written, built and run entirely on the phone.)

Given the experience, I am inclined to rewrite the code to eliminate QScrollArea altogether and instead do my own redrawing the preview with moving starting point. What options do I have to drag the picture left or right with the finger? I would really prefer not to try implementing my own version of kinetic scrolling if I can.

jackburton 2014-07-16 21:15

Re: How do I make a scrollable gui with QtCreator?
 
Quote:

Originally Posted by pichlo (Post 1433055)
Is reviving a 3yo thread better or worse than creating a new one? :)

Anyway, I have a QScrollArea that covers most of the screen. Inside it, I have a widget of type Preview, derived from QGLWidget.

I also have zoom buttons. Zoom affects the horizontal size only, the vertical dimension is fixed. The problem is that zooming in more than two times segfaults the program.

Here is the relevant bit where it segfaults:
Code:

void Preview::paintGL ()
{
  QPainter painter(this);
  painter.setRenderHint(QPainter::Antialiasing, true);

  const int w = width();
  const int h = height();

  // Paint the background
  painter.fillRect(0, 0, w, h, Qt::white);

  // ... a few dozen more lines ...

  painter.end();
}

It crashes on the painter.fillRect line, as verified by sticking qDebug before and after. Values of w and h were:

w=668, h=416, OK (starting point)
w=1002, h=416, OK (zoom in x1)
w=1503, h=416, OK (zoom in x2)
w=2254, h=416, crash!

What is going on? Can the device not handle painting areas of that size? (Code written, built and run entirely on the phone.)

Given the experience, I am inclined to rewrite the code to eliminate QScrollArea altogether and instead do my own redrawing the preview with moving starting point. What options do I have to drag the picture left or right with the finger? I would really prefer not to try implementing my own version of kinetic scrolling if I can.

Interesting problem. I haven't done Qt in a while. Do you have any source to test with? Is this Maemo 5?

You may also find hints in the Qalendar source code. The author does a lot of his own drawing in there. Very clean code.

marxian 2014-07-16 21:16

Re: How do I make a scrollable gui with QtCreator?
 
I did a simple test using a QScrollArea and a plain QWidget, and was able to continue expanding the size of the widget without any problem:

http://t.imgbox.com/Pu1qY7vF.jpg

Perhaps you could try substituting the QGLWidget for a QWidget to see if the problem is related to QGLWidget.

It might also be worth showing the setup code for the QScrollArea and child widget (do you have 'widgetResizable' enabled and so on).

pichlo 2014-07-16 21:44

Re: How do I make a scrollable gui with QtCreator?
 
Here are the initializing bits:

1) mainwindow.ui (relevant part only)
Code:

      <item>
      <widget class="QScrollArea" name="scrollArea">
        <property name="widgetResizable">
        <bool>true</bool>
        </property>
      </widget>
      </item>

2) mainwindow.h (simplified)
Code:

#include "stackedmainwindow.h"
#include "ui_mainwindow.h"
#include "preview.h"

class MainWindow : public StackedMainWindow
{
  Q_OBJECT

public:
  explicit MainWindow (QWidget *parent = 0);

private slots:
  void on_buttonZoomHome_clicked ();
  void on_buttonZoomIn_clicked ();
  void on_buttonZoomOut_clicked ();

private:
  Ui::MainWindow ui;
  Preview preview;
  double scaleFactor;
};

3) mainwindow.cpp (simplified)
Code:

MainWindow::MainWindow (QWidget *parent)
  : StackedMainWindow(parent)
  , preview(this)
  , scaleFactor(1.0)
{
  ui.setupUi(this);
  ui.scrollArea->setWidget(&preview);
}

I will try replacing QGLWidget with QWidget. It might be a QGLWidget problem after all, not QScrollArea one. In the meantime, I made another experiment with the only thing changed is reducing the scale factor from 1.5 to 1.25. The result...

w=668, h=424
w=835, h=416
w=1043, h=416
w=1043, h=416
w=1304, h=416
w=1630, h=416
w=2038, h=416
w=2548, h=416, crash!

So it does seem to be size related.

Copernicus 2014-07-16 22:38

Re: How do I make a scrollable gui with QtCreator?
 
Another item to test: you could try just placing the Preview widget directly into the UI without embedding it within a QScrollArea widget. I kind of get the feeling that if this is a memory overrun or a clipping error, it'd be more likely to happen closer to the widget with the actual image data. I kind of doubt that QScrollArea would be so sensitive to the physical size of the image...

BTW, on kinetic scrolling: it seems you can enable kinetic scrolling on most any Qt Maemo widget that can scroll. You can manipulate this feature (turning it on or off, retrieving various scrolling info, or messing around with it in general) by accessing the "kineticScroller" property of the widget. For example, this would switch on kinetic scrolling for a widget called "scrollArea":

Code:

QAbstractKineticScroller *scroller = scrollArea->property("kineticScroller").value<QAbstractKineticScroller *>();

 if (scroller)
    scroller->setEnabled(true);

There's a bunch more info in the Qt docs about this. :)

marxian 2014-07-16 22:52

Re: How do I make a scrollable gui with QtCreator?
 
Quote:

Originally Posted by Copernicus (Post 1433072)
BTW, on kinetic scrolling: it seems you can enable kinetic scrolling on most any Qt Maemo widget that can scroll.

I think the only widgets that can scroll are those derived from QAbstractScrollArea (QScrollArea and the item views/widgets) and QWebView. Those are the only widgets I know of that have a QAbstractKineticScroller.

jflatt 2014-07-16 23:09

Re: How do I make a scrollable gui with QtCreator?
 
Max texture size and max render buffer on SGX 530 is 2048x2048


All times are GMT. The time now is 13:14.

vBulletin® Version 3.8.8