Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Widget container or layout with free positioning of widgets and with scroll bars
Forum Updated to NodeBB v4.3 + New Features

Widget container or layout with free positioning of widgets and with scroll bars

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mufflon
    wrote on last edited by
    #1

    hi,
    i already tried a lot but without luck and i searched for similar problems and solutions...

    i've got a window with a vertical layout which has two horizontal layouts with some widgets.
    what i want to build is a part (see it at the bottom of the picture) with some widgets where i can set the size of and the position them.

    it shall be some kind of timeline but it's not only for painting these boxes, the user should be able to click them and the program should react....so i guess it's better if these are widgets rather than it's "only" a painting.

    do you have any hint for me how to solve this problem?

    !http://kalubis.free.fr/qtlayout.png!

    1 Reply Last reply
    0
    • T Offline
      T Offline
      thEClaw
      wrote on last edited by
      #2

      Maybe use a "QScrollArea":http://qt-project.org/doc/qt-5.1/qtwidgets/qscrollarea.html with a "QGridLayout":http://qt-project.org/doc/qt-5.1/qtwidgets/qgridlayout.html inside? Alternatively, you can position widgets completely without a layout - assign a parent, call their QWidget::move() (coordinates relative to parent) function and QWidget::show() them. But that's very unflexible.

      Or do you want to be able to drag the widgets around via mouse? That would be possible, too. First step should be a QScrollArea nonetheless. Next step would be to reimplement some functions (mousePressEvent, dropEvent, ...). I would suggest one of "these examples":http://qt-project.org/doc/qt-5.1/qtdoc/examples-draganddrop.html for that.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi and welcome to devnet,

        You might also be interested by "the graphics view framework":http://qt-project.org/doc/qt-4.8/qgraphicsview.html

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mufflon
          wrote on last edited by
          #4

          Thanks for the replies. I got a solution now.
          I already tried to use a QScrollArea but my problem was that I could only add one widget and i didn't have any luck with added layouts to to work with the scrollbars.
          That is what i tried:
          @ QGridLayout* lay = new QGridLayout(ui->scrollArea1);
          ui->scrollArea1->setLayout(lay);
          QImage* img = new QImage(800,800, QImage::Format_ARGB32);
          img->load("test.png");

          QLabel* myLabel = new QLabel();
          myLabel->setPixmap(QPixmap::fromImage(*img));
          myLabel->setMinimumSize(200,200);
          myLabel->setGeometry(QRect(300,300,200,200));
          
          
          lay->addWidget(myLabel);@
          

          In my new solution I will use a label as background set as widget in the scrollarea and i will set the parent of the other time-bar-labels to the background labels:

          @ QLabel* myLabel = new QLabel();
          myLabel->setMinimumSize(800,400);
          myLabel->setStyleSheet("QLabel { background-color : white; color : black; }");

          ui->scrollArea1->setWidget(myLabel);
          
          
          QLabel* myLabel2 = new QLabel("Label");
          myLabel2->setParent(myLabel);
          
          myLabel2->setStyleSheet("QLabel { background-color : red; color : black; }");
          
          myLabel2->setGeometry(QRect(50,50,200,20));@
          

          I will also look at the QGraphicsView class.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved